fix: 终端 ⌘V 粘贴图片失效(#27 回归) - #50
Open
znlnzi wants to merge 2 commits into
Open
Conversation
alchaincyf#27 的复制粘贴修复给 ⌘V 加了自定义处理器,只在 readText() 拿到非空文本时 才调 xterm.paste。但图片粘贴靠的是 claude 收到粘贴信号(bracketed paste 序列)后主动读系统剪贴板取图;纯图片剪贴板的 readText() 返回空串/reject, 于是 xterm.paste 从不被调用,claude 收不到信号,图片粘贴回归失效。 改为无论文本是否为空都 xterm.paste(text || ''),reject 分支同样补发 xterm.paste(''),还原 alchaincyf#27 之前的行为。空 bracketed paste 对 shell/claude 是无害 no-op,仅作为让 claude 去读剪贴板的触发信号;文本粘贴与 ⌘C 复制不受影响。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
前一提交让 ⌘V 处理器对空文本也 xterm.paste('') 发 bracketed-paste 信号
以修复图片粘贴,但撞上了 xterm 自带的原生 paste 监听:同一次按键两条路径
各发一遍空信号,claude 便读两次系统剪贴板 → 图片粘两张。Cmd+V 时 preventDefault
顺带压掉了原生事件,Ctrl+V 压不住,故只有 Ctrl+V 双发。
键盘接管粘贴时打时间戳,捕获阶段一次性拦掉紧随其后(<60ms)的那次原生 paste,
避免双发;拦截时把原生事件携带的 clipboardData 文本存下,供 readText 失败时兜底,
不丢文本粘贴。鼠标点「编辑→粘贴」无前置按键戳,不拦,保持可用。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
自 #27(终端复制粘贴修复)起,在终端里对 claude 等 TUI 按 ⌘V 粘贴图片失效;粘贴文本正常。
根因
#27 给 ⌘V 加了自定义键盘处理器(
public/app.js),只在readText()拿到非空文本时才调xterm.paste:图片粘贴的机制是:终端把 bracketed-paste 信号(
\x1b[200~…\x1b[201~)发给 PTY,claude 收到后主动读系统剪贴板取图。纯图片剪贴板的readText()返回空串/reject,if (text)为假 →xterm.paste从不触发 → claude 收不到信号 → 不读剪贴板 → 图片粘贴失效。修复
无论文本是否为空都转发
xterm.paste(text || ''),reject 分支补发xterm.paste(''),还原 #27 之前 xterm 默认粘贴路径。影响面
文本粘贴、⌘C 复制、字号缩放、右键菜单均不受影响。空 bracketed paste 对 shell/claude 是无害 no-op,仅作触发信号。
🤖 Generated with Claude Code