From 59d50af05ee0f562e6382b6924d32b9a7bc973e0 Mon Sep 17 00:00:00 2001 From: cravenceiling <53354136+cravenceiling@users.noreply.github.com> Date: Thu, 29 Jan 2026 19:07:44 -0500 Subject: [PATCH] fix(tui): allow pasting strings with image extensions Only call preventDefault() after confirming the file exists and it's an image. --- .../cli/cmd/tui/component/prompt/index.tsx | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx index e19c8b7098..45e5410e38 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx @@ -503,9 +503,9 @@ export function Prompt(props: PromptProps) { const sessionID = props.sessionID ? props.sessionID : await (async () => { - const sessionID = await sdk.client.session.create({}).then((x) => x.data!.id) - return sessionID - })() + const sessionID = await sdk.client.session.create({}).then((x) => x.data!.id) + return sessionID + })() const messageID = Identifier.ascending("message") let inputText = store.prompt.input @@ -594,7 +594,7 @@ export function Prompt(props: PromptProps) { })), ], }) - .catch(() => {}) + .catch(() => { }) } history.append({ ...store.prompt, @@ -887,20 +887,20 @@ export function Prompt(props: PromptProps) { const file = Bun.file(filepath) // Handle SVG as raw text content, not as base64 image if (file.type === "image/svg+xml") { - event.preventDefault() - const content = await file.text().catch(() => {}) + const content = await file.text().catch(() => { }) if (content) { + event.preventDefault() pasteText(content, `[SVG: ${file.name ?? "image"}]`) return } } if (file.type.startsWith("image/")) { - event.preventDefault() const content = await file .arrayBuffer() .then((buffer) => Buffer.from(buffer).toString("base64")) - .catch(() => {}) + .catch(() => { }) if (content) { + event.preventDefault() await pasteImage({ filename: file.name, mime: file.type, @@ -909,7 +909,7 @@ export function Prompt(props: PromptProps) { return } } - } catch {} + } catch { } } const lineCount = (pastedContent.match(/\n/g)?.length ?? 0) + 1 @@ -980,13 +980,13 @@ export function Prompt(props: PromptProps) { customBorderChars={ theme.backgroundElement.a !== 0 ? { - ...EmptyBorder, - horizontal: "▀", - } + ...EmptyBorder, + horizontal: "▀", + } : { - ...EmptyBorder, - horizontal: " ", - } + ...EmptyBorder, + horizontal: " ", + } } />