From f7a97666365ba09f7c7dc4e3256714c9e7ff61f3 Mon Sep 17 00:00:00 2001 From: code_programmer <51956683+17361564318@users.noreply.github.com> Date: Fri, 20 Mar 2026 15:58:40 +0800 Subject: [PATCH] fix(bug) paste image --- .../cli/cmd/tui/component/prompt/index.tsx | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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 249a48d358b..8f15deb5d65 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx @@ -930,6 +930,28 @@ export function Prompt(props: PromptProps) { event.preventDefault() return } + // ===== 新增:检测剪贴板图片二进制数据 ===== + // Windows 终端无法通过 bracketed paste 传输图片二进制数据 + // 需要直接从 clipboardData 检测图片 + if (event.clipboardData?.items) { + for (const item of event.clipboardData.items) { + if (item.type.startsWith("image/")) { + event.preventDefault() + const file = item.getAsFile() + if (file) { + const buffer = await file.arrayBuffer() + const base64 = Buffer.from(buffer).toString("base64") + await pasteImage({ + filename: "clipboard", + mime: item.type, + content: base64, + }) + return + } + } + } + } + // ===== 新增结束 // Normalize line endings at the boundary // Windows ConPTY/Terminal often sends CR-only newlines in bracketed paste