fix(tui): paste into active custom answers (#44849)

Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
This commit is contained in:
opencode-agent[bot] 2026-08-25 18:19:28 +05:30 committed by GitHub
parent e3aa13c7d0
commit 5c25c38961
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 1 deletions

View file

@ -329,7 +329,13 @@ export function FormPrompt(props: { form: FormWithLocation }) {
usePaste((event) => {
if (keymap.mode.current() !== FORM_MODE) return
if (!pasteCustom(stripAnsiSequences(decodePasteBytes(event.bytes)).replace(/\r\n?/g, "\n"))) return
const value = stripAnsiSequences(decodePasteBytes(event.bytes)).replace(/\r\n?/g, "\n")
if (store.editing && renderer.currentFocusedEditor === textarea) {
textarea.insertText(value)
event.preventDefault()
return
}
if (!pasteCustom(value)) return
event.preventDefault()
})

View file

@ -310,6 +310,35 @@ test("pasting on a custom choice opens its editor without submitting", async ()
}
})
test("pasting in an active custom editor inserts at the cursor", async () => {
await using tmp = await tmpdir()
const prompt = await mountForm(tmp.path, 80, [
{
key: "target",
type: "string",
options: [{ value: "staging", label: "Staging" }],
custom: true,
},
])
try {
prompt.app.mockInput.pressArrow("down")
prompt.app.mockInput.pressEnter()
await prompt.app.waitFor(() => prompt.app.renderer.currentFocusedEditor !== null)
await prompt.app.mockInput.typeText("prodwest")
const editor = prompt.app.renderer.currentFocusedEditor
if (editor) editor.cursorOffset = 4
await prompt.app.mockInput.pasteBracketedText("uction ")
await prompt.app.waitFor(() => prompt.app.renderer.currentFocusedEditor?.plainText === "production west")
await prompt.app.mockInput.typeText("!")
expect(prompt.app.renderer.currentFocusedEditor?.plainText).toBe("production !west")
expect(prompt.replies).toEqual([])
} finally {
prompt.app.renderer.destroy()
}
})
test("clipboard shortcut opens a custom choice editor without submitting", async () => {
await using tmp = await tmpdir()
const prompt = await mountForm(