Skip to content

fix(terminal): let Shift+middle-click paste in mouse-tracking panes - #21858

Merged
buf0-bot[bot] merged 2 commits into
mainfrom
terminal-shift-middle-click-paste
Sep 21, 2026
Merged

buf0-bot[bot] merged 2 commits into
mainfrom
terminal-shift-middle-click-paste

Conversation

@buf0-bot

@buf0-bot buf0-bot Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​105 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​103
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​14

ELI5

Holding Shift while middle-clicking is the long-standing terminal trick for "ignore the app running in here, just do the normal terminal thing". A fix I merged yesterday (#21834) accidentally made that gesture paste nothing at all in terminals running a full-screen app like Claude Code. This restores it.

What Changed

Before: Shift+middle-click in a pane running a mouse-tracking TUI pasted nothing.

After: it pastes the primary selection once, as it did before #21834 — and now via Orca's own paste path, which is more reliable than depending on the browser's native paste.

The mechanism. xterm deliberately withholds the mouse report for a shifted click, so the TUI never learns the click happened and never pastes. Concretely, MouseService._handleMouseDown returns early when SelectionService.shouldForceSelection(ev) is true, and that method ends in return event.shiftKey on non-Mac.

#21834 taught the middle-click handler to always arm the native-paste suppression window (that was the whole point — it stops Chromium's native paste from duplicating the TUI's own paste). But it also kept returning early for every click in a tracking pane. For a shifted click that combination is fatal: Orca swallows the native paste, and the TUI never gets a report to paste from, so both candidates are gone.

The fix narrows that early return. It now applies only when the click will actually reach the TUI — i.e. tracking mode and the modifier is not one that makes xterm withhold the report. A shifted click falls through to Orca's normal paste-to-PTY branch instead.

The new terminalForcesSelectionForClick helper mirrors xterm's own rule rather than hardcoding Shift, so Orca and xterm always agree on who owns the click: Shift on Linux/Windows, Option on Mac (Orca sets macOptionClickForcesSelection: true in pane-terminal-options.ts, and xterm's Mac branch is altKey && macOptionClickForcesSelection). Without the Mac branch, a Mac user with this setting enabled would get a double paste on Shift+middle-click — Orca's own plus the TUI's — since Mac does forward shifted clicks to the TUI. (Not #21762's exact mechanism, whose native-paste half is Linux-only, but the same visible symptom.)

Why

The alternative — special-casing Shift only on Linux — would silently break Mac, where Shift is forwarded and Option is the withholding modifier. Mirroring shouldForceSelection keeps one source of truth for the question "will xterm forward this click?", so the two components cannot drift apart.

This also composes correctly with the terminal link feature from #21438: its isTerminalMiddleClickActivation already requires !shiftKey, so a shifted click was never a link gesture and nothing is taken away from it.

Linked Issue

Follow-up to #21834 / #21762 — fixes a regression introduced there, found during post-merge review.

Refs #21762

Visual Proof

N/A — input-handling fix with no rendered UI change. The observable difference is "Shift+middle-click pastes once" vs. "pastes nothing" in a terminal running a mouse-tracking TUI.

Testing

  • Automated tests added/updated

Extended issue-21762-tracking-mode-middle-click-double-paste.repro.test.ts with five cases: Shift in a tracking pane takes the paste path; unshifted in a tracking pane is unchanged (proves #21762 is not regressed); Alt+middle-click off Mac stays on the TUI-owned path (guards against collapsing the check to shiftKey || altKey); the auxclick handler matches; and on a Mac user agent Shift does not take the paste path while Option does.

Verified the tests actually catch the bug rather than merely passing: with the source change reverted and the new tests kept, the three fix-dependent tests fail on propagationStopped; with the fix restored, all six pass.

  • 20 files / 209 tests pass across the repro, usePrimarySelectionPaste*, primary-selection*, and all terminal-link-* suites.
  • pnpm tc:web clean; pnpm run check:code-quality:changed passes all seven gates.
  • Not manually exercised against a live Linux desktop session; the behavior is pinned by the unit tests plus the xterm source references above.

AI Disclosure

Authored by Claude (Anthropic) in Claude Code, following post-merge review of #21834.

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

  • Cross-platform: explicitly handled — the modifier differs on Mac and is mirrored from xterm's rule.
  • Security: no change to what is read or suppressed; only which branch a click takes.
  • SSH/remote & mobile: unaffected; this is renderer-side gesture routing ahead of any transport.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Follow-up to #21834 (issue #21762). That fix arms the native-paste
suppression window for every terminal middle-click, then returns early
when the pane is in mouse-tracking mode so the TUI performs the paste
from the forwarded mouse report.

xterm's SelectionService.shouldForceSelection deliberately withholds
that report for a shifted click (Option-click on Mac), so the TUI never
pastes. With the native follow-up paste now suppressed as well,
Shift+middle-click in Claude Code, Codex, and other tracking TUIs pasted
nothing at all. Previously Chromium's native paste was the one paste.

Mirror xterm's platform rule: when the click's modifier forces
selection, fall through to Orca's own paste-to-PTY path (stop
propagation, focus, paste) exactly as in a non-tracking pane. The
auxclick handler gates stopPropagation the same way.
@pullfrog

pullfrog Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

This run was cancelled 🛑

The workflow was cancelled before completion. Please check the link below for details.

Pullfrog  | View workflow run | via Pullfrog | 𝕏

@buf0-bot
buf0-bot Bot merged commit 41f34f6 into main Sep 21, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants