Fix text selection in mouse-tracking sessions on macOS - #81
Merged
Conversation
A TUI that turns on mouse tracking (CSI ?1002h / ?1003h) makes xterm.js forward every drag to the application, so no text can be selected. Terminal.app and iTerm2 let you hold Option to override that; xterm.js gates the same escape hatch behind macOptionClickForcesSelection, which defaults to false. The symptom is misleading: Cmd+C finds no selection, so xterm's copy handler is a no-op and fails silently, leaving the previous clipboard contents in place. The next paste then inserts stale text and reads as a broken paste. Windows and Linux are unaffected — there the override is Shift, which needs no option.
Bono2007
force-pushed
the
fix/macos-selection-mouse-tracking
branch
from
July 27, 2026 11:13
571a088 to
35c567d
Compare
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.
Problem
Text cannot be selected with the mouse on macOS in any session running a TUI that enables mouse tracking, which makes copying impossible.
When an application turns on mouse tracking (
CSI ?1002h/CSI ?1003h), xterm.js forwards every drag to that application instead of starting a selection. Terminal.app and iTerm2 let you hold Option to override the convention, but xterm.js gates the same escape hatch behindmacOptionClickForcesSelection, which defaults tofalseand was never set here.The symptom users report is misleading.
Cmd+Cfinds no selection, so xterm's copy handler is a no-op and it fails silently — the previous clipboard contents stay in place. The next paste then inserts stale text, which reads as "paste is broken" even though the paste path itself is fine.Reproduction
Measured against the live renderer over the Chrome DevTools Protocol, driving synthetic mouse and key events. The session runs
vim -c "set mouse=a"on a file containing one known line:Same gesture, same session, only the option toggled — which isolates the cause. Plain drag correctly keeps going to the application in both states, so mouse-driven TUIs stay usable.
Fix
One option on the xterm instance in
public/terminal-manager.js:Windows and Linux were never affected — there
shouldForceSelectionkeys off Shift, which needs no option.Verification
Cmd+C→Cmd+Vreturns the selected line intact.npm testpasses,npm run bundle:codemirrorsucceeds.Trade-off
Enabling this flag disables Option+drag rectangular (column) selection on macOS, since xterm's
shouldColumnSelectandshouldForceSelectionshare the same modifier. This is the standard trade-off and matches iTerm2's default behaviour.Related
Distinct from #54 / #55, which cover copy on Linux/Wayland via OSC 52. Worth noting separately that Switchboard doesn't handle OSC 52 at all, so an application's own clipboard requests are dropped — out of scope here.