Repository navigation
fix(terminal): stop native middle-click paste inserting twice on Linux - #8993
Conversation
📝 WalkthroughWalkthroughAdds timed primary-selection native-paste suppression. Terminal middle-click handling arms the state, while 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
second paste comes from CLIPBOARD, not PRIMARY |
|
Thanks for the repro details. I checked this path and updated the wording in the branch/title to avoid making the fix sound X11/PRIMARY-only. The implementation intentionally suppresses the short-lived native paste follow-up after Orca has already handled the terminal middle-click paste. That suppression is based on the armed middle-click window rather than the clipboard source, because the renderer paste/beforeinput events do not reliably expose whether the text came from PRIMARY or CLIPBOARD. So the Wayland/Fedora case where the follow-up inserts CLIPBOARD text should be covered too. Verified locally with: pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/hooks/usePrimarySelectionPaste.test.tsx src/renderer/src/lib/primary-selection.test.tsResult: 2 files / 18 tests passed. |
When "Middle-click Paste from Selection" is enabled, the integrated terminal reads the X11 PRIMARY selection on mousedown and writes it to the PTY itself. It calls preventDefault on the mousedown, but Chromium's native X11 middle-click primary paste fires on mouse release regardless, landing in xterm's helper textarea, which xterm then forwards to the PTY a second time. The result is the selection pasted twice. The global primary-selection hook already suppresses the follow-up native paste, but only for editable DOM targets it owns via a pending-target handle; it deliberately excludes xterm, so the terminal path had no suppression at all. Arm a short shared suppression window when the terminal handles a middle-click, and have the global hook's capture-phase beforeinput/paste suppressor honor it. This swallows the single native paste event so the selection reaches the PTY exactly once. Ctrl+Shift+V and right-click paste are unaffected: they use the CLIPBOARD and never emit a native primary-paste event. Closes stablyai#8860
…nux xterm Gate the armed native-paste suppression window to Linux (X11 primary-selection path) and scope it to xterm's helper textarea so unrelated document pastes and non-Linux platforms are never affected. Re-arm on auxclick for slow releases. Co-authored-by: Orca <[email protected]>
040e2ee to
8d3eb62
Compare
|
Thanks so much for this, @xianjianlf2 — stop native middle-click paste inserting twice on Linux. Verified (fail-on-main/pass-on-branch), rebased on latest |
…tracking TUIs (#21834) * fix(terminal): arm native-paste suppression on middle-click in mouse-tracking TUIs (#21762) Orca's own middle-click paste path bailed out entirely whenever the pane was in mouse tracking mode (Claude Code, Codex, ...), skipping preventDefault() and never arming the #8993 native-paste suppression window. Chromium's native Linux middle-click paste then landed unsuppressed alongside the TUI's own PRIMARY paste from the forwarded mouse report, pasting the selection twice. Split pane lookup from the tracking-mode gate: any terminal pane target now arms suppression and blocks the native paste, while only the paste-to-PTY (and the propagation stop that would swallow the click before xterm can report it) stays gated on mouseTrackingMode === 'none'. * fix(terminal): address review nits on the #21762 middle-click fix - Fix a mis-attributing comment: the suppression window (not preventDefault, which only helps on mousedown while Chromium's native paste fires on mouseup) is what swallows the duplicate native paste. - Drop the now-unused getPrimarySelectionMiddleClickPane. - Assert stopPropagation is/isn't called per tracking mode in the repro test. --------- Co-authored-by: bench <[email protected]>
stablyai#8993) * fix(terminal): stop middle-click primary paste inserting twice on X11 When "Middle-click Paste from Selection" is enabled, the integrated terminal reads the X11 PRIMARY selection on mousedown and writes it to the PTY itself. It calls preventDefault on the mousedown, but Chromium's native X11 middle-click primary paste fires on mouse release regardless, landing in xterm's helper textarea, which xterm then forwards to the PTY a second time. The result is the selection pasted twice. The global primary-selection hook already suppresses the follow-up native paste, but only for editable DOM targets it owns via a pending-target handle; it deliberately excludes xterm, so the terminal path had no suppression at all. Arm a short shared suppression window when the terminal handles a middle-click, and have the global hook's capture-phase beforeinput/paste suppressor honor it. This swallows the single native paste event so the selection reaches the PTY exactly once. Ctrl+Shift+V and right-click paste are unaffected: they use the CLIPBOARD and never emit a native primary-paste event. Closes stablyai#8860 * docs(terminal): clarify native middle-click paste suppression * fix(terminal): scope primary-selection native-paste suppression to Linux xterm Gate the armed native-paste suppression window to Linux (X11 primary-selection path) and scope it to xterm's helper textarea so unrelated document pastes and non-Linux platforms are never affected. Re-arm on auxclick for slow releases. Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Neil <[email protected]> Co-authored-by: Orca <[email protected]>
Summary
Fixes middle-click paste in the integrated terminal inserting the PRIMARY selection twice on Linux/X11 when "Middle-click Paste from Selection" is enabled.
ELI5
On Linux, middle-clicking the terminal to paste used to type your copied text twice. Now it pastes exactly once, like you'd expect.
Root cause & fix
The terminal reads the PRIMARY selection on mousedown and writes it to the PTY itself, calling
preventDefault(). But Chromium's native X11 middle-click primary paste still fires on mouse release, landing in xterm's helper textarea, which forwards it to the PTY a second time. The globalusePrimarySelectionPastehook already suppresses this native follow-up, but only for editable targets it owns — it excludes xterm, leaving the terminal path unsuppressed. The fix arms a short shared suppression window (armPrimarySelectionNativePasteSuppression) when the terminal handles a middle-click, and has the hook's capture-phasebeforeinput/pastesuppressor honor it. The single native paste is swallowed; the selection reaches the PTY once.Ctrl+Shift+Vand right-click paste (CLIPBOARD, no native primary-paste event) are unchanged.Evidence
Validated & rebased onto latest main during a bug-bash triage on 2026-07-23.
Trade-offs
None — pure fix.
Regression risk
Low. The suppression only fires inside a briefly-armed window opened by a terminal middle-click;
Ctrl+Shift+Vand right-click paste take a different path and are unaffected. The new behavior is proven by the passing suppression and negative-case tests.Credit to original author @xianjianlf2. Validated and rebased onto latest main via automated bug-bash review; original fix design preserved.