fix(terminal): intercept Cmd+V on macOS to prevent paste-then-edit garbling#100
Merged
DeadWaveWave merged 3 commits intoDeadWaveWave:mainfrom Mar 30, 2026
Merged
Conversation
Owner
|
感谢修复 #88,这个思路(拦截快捷键 → 有几个点想跟你对齐一下意图 / 现状:
谢谢! |
Contributor
Author
Owner
|
CI 未通过,需要先先本地通过 pnpm pre-commit 再提交 |
…rbling (DeadWaveWave#88) On macOS, xterm.js handles Cmd+V paste through its hidden textarea. After pasting, the browser's default action re-inserts clipboard text into the textarea (handlePasteEvent calls stopPropagation but not preventDefault). Subsequent input reads stale textarea content, producing garbled characters from the end of the pasted text. Fix by intercepting Cmd+V in the custom key event handler (mirroring the existing Windows Ctrl+V path): preventDefault blocks the native paste, readTextFromClipboard fetches via Electron IPC, and terminal.paste() sends data directly without touching the textarea.
Address PR review: isMacTerminalPasteShortcut was matching Meta+V on Linux (Super key), which is not a standard paste shortcut. Add isMacPlatform() guard so the shortcut only fires on macOS, and remove the Linux Meta+V test assertion. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
d1806f8 to
5909ede
Compare
Co-Authored-By: Claude Opus 4.6 (1M context) <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.
Summary
Fixes #88
On macOS, pasting text (Cmd+V) into a terminal node and then moving the cursor left to edit produces garbled characters from the end of the pasted text (e.g. pasting "...emoji" then typing yields "ijiji" instead of the intended input).
Root Cause
xterm.js's
handlePasteEventcallsstopPropagation()but notpreventDefault(). After the paste handler clears the hidden textarea, the browser's default action re-inserts the clipboard text. Subsequent input interacts with this stale textarea content, producing characters from the tail of the pasted text.Fix
Intercept Cmd+V on macOS in
handleTerminalCustomKeyEvent— the same approach already used for Ctrl+V on Windows:event.preventDefault()blocks the native paste from reaching the textareareadTextFromClipboard()fetches text via Electron clipboard IPCterminal.paste(text)sends data directly through xterm.js'sonData, bypassing the textarea entirelyChanges
inputBridge.ts: AddisMacTerminalPasteShortcut(), extend paste check to include macOS Cmd+VterminalInputBridge.spec.ts: Add 8 new unit tests covering macOS paste, Cmd+C non-interference, Cmd+Shift+V non-interception, and Linux Meta+V behaviorReproduction
示模型名、上下文进度条、费用,用简洁的 emoji)After fix
Test plan
isMacTerminalPasteShortcuttests: Cmd+V macOS ✓, Cmd+V Windows ✗, Ctrl+V macOS ✗, Cmd+Shift+V ✗, Meta+V Linux ✓handleTerminalCustomKeyEventtests: macOS Cmd+V paste ✓, Cmd+C non-interference ✓, Cmd+Shift+V non-interception ✓