Description
Pasting text into the TUI prompt collapses it into a [Pasted ~N lines] placeholder, with the real text stored on the prompt part. When that placeholder is expanded back to the full text, the pasted text is passed as the replacement string to String.prototype.replace. A string replacement interprets $ sequences ($$, $&, $`, $'), so pasted code that contains them comes back altered.
Two flows are affected: copying the prompt back to the clipboard, and opening the prompt in the external editor. The submit path is fine because it uses the range-based expander.
Examples (pasted text on the left, what you get back on the right):
const x = ${a}$$ becomes const x = ${a}$ (the $$ collapses to one $)
echo $&done becomes echo [Pasted ~N lines]done ($& re-inserts the placeholder string into the code)
$` and $' are mangled the same way (they pull in text from around the placeholder)
OpenCode version
dev (1.17.9)
Steps to reproduce
- Paste a multi-line block containing
$$ or $& (shell or template-literal code, for example) into the prompt so it collapses to [Pasted ~N lines].
- Copy the prompt to the clipboard, or open it in the external editor.
- The text you get back differs from what you pasted.
Description
Pasting text into the TUI prompt collapses it into a
[Pasted ~N lines]placeholder, with the real text stored on the prompt part. When that placeholder is expanded back to the full text, the pasted text is passed as the replacement string toString.prototype.replace. A string replacement interprets$sequences ($$,$&,$`,$'), so pasted code that contains them comes back altered.Two flows are affected: copying the prompt back to the clipboard, and opening the prompt in the external editor. The submit path is fine because it uses the range-based expander.
Examples (pasted text on the left, what you get back on the right):
const x = ${a}$$becomesconst x = ${a}$(the$$collapses to one$)echo $&donebecomesecho [Pasted ~N lines]done($&re-inserts the placeholder string into the code)$`and$'are mangled the same way (they pull in text from around the placeholder)OpenCode version
dev (1.17.9)
Steps to reproduce
$$or$&(shell or template-literal code, for example) into the prompt so it collapses to[Pasted ~N lines].