Compare commits

...

1 Commits

Author SHA1 Message Date
Shoubhit Dash 177370dae0 fix(tui): paste into custom form answers 2026-08-18 13:13:51 +00:00
2 changed files with 42 additions and 2 deletions
+12
View File
@@ -523,6 +523,18 @@ export function FormPrompt(props: {
textarea?.setText("")
},
},
{
id: "prompt.paste",
title: "Paste into answer",
group: "Form",
async run(_input, event) {
event?.preventDefault()
event?.stopPropagation()
const content = await clipboard.read()
if (content?.mime !== "text/plain") return
textarea?.insertText(content.data)
},
},
{
bind: "escape",
title: textual() ? "Dismiss form" : "Close answer edit",
+30 -2
View File
@@ -14,7 +14,7 @@ import { TestTuiContexts } from "../../fixture/tui-environment"
import { createTuiResolvedConfig } from "../../fixture/tui-runtime"
import { createApi, createEventStream, createFetch } from "../../fixture/tui-client"
async function mountForm(root: string, width = 80, fields?: FormWithLocation["fields"], height = 20) {
async function mountForm(root: string, width = 80, fields?: FormWithLocation["fields"], height = 20, pasted?: string) {
const state = path.join(root, "state")
await mkdir(state, { recursive: true })
@@ -58,7 +58,7 @@ async function mountForm(root: string, width = 80, fields?: FormWithLocation["fi
}}
clipboard={{
async read() {
return undefined
return pasted ? { data: pasted, mime: "text/plain" } : undefined
},
write(text) {
copied.push(text)
@@ -217,6 +217,34 @@ test("pasting on a custom choice opens its editor without submitting", async ()
}
})
test("ctrl-v pastes clipboard text into a custom answer", async () => {
await using tmp = await tmpdir()
const prompt = await mountForm(
tmp.path,
80,
[
{
key: "target",
type: "string",
options: [{ value: "staging", label: "Staging" }],
custom: true,
},
],
20,
"production west",
)
try {
prompt.app.mockInput.pressArrow("down")
prompt.app.mockInput.pressEnter()
await prompt.app.waitFor(() => prompt.app.renderer.currentFocusedEditor !== null)
prompt.app.mockInput.pressKey("v", { ctrl: true })
await prompt.app.waitFor(() => prompt.app.renderer.currentFocusedEditor?.plainText === "production west")
} finally {
prompt.app.renderer.destroy()
}
})
test("typing a custom multiselect answer selects it before commit", async () => {
await using tmp = await tmpdir()
const prompt = await mountForm(tmp.path, 80, [