mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-26 11:51:56 +00:00
fix(tui): paste into active custom answers (#44849)
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
This commit is contained in:
parent
e3aa13c7d0
commit
5c25c38961
2 changed files with 36 additions and 1 deletions
|
|
@ -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()
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue