Repository navigation
feat(terminal): right-click copies the selection or pastes - #338
Merged
amirlehmam merged 1 commit intoOct 23, 2026
Merged
Conversation
…m#336) Right-click in a terminal pane did nothing: no `contextmenu` handler existed and Electron shows no default menu, so the gesture every Windows console (conhost QuickEdit, Windows Terminal, PuTTY, mintty) uses for the clipboard was dead. - terminalPrefs.rightClick: copyPaste (default, Windows Terminal behaviour), paste, or off - an app with mouse tracking on (vim mouse=a, tmux, htop) keeps the click; Shift is the bypass, which costs nothing because xterm's shouldForceSelection is shiftKey, so no report is sent with Shift held - paste goes through the SAME resolver as Ctrl+V, so bracketed paste, image and file paste and scp for an ssh pane (amirlehmam#195) all come along; copy trims trailing whitespace like Ctrl+C (amirlehmam#102) The decision is a pure rightClickAction() in utils/terminal-right-click.ts; the listener sits on the xterm container only, so the overlays above it keep their own clicks.
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.
Closes #336
Problem
Right-click inside a terminal pane did nothing. No
contextmenuhandler existed on the xterm container and Electron shows no default menu, so the gesture every Windows console uses for the clipboard — conhost QuickEdit, Windows Terminal, PuTTY, mintty — was dead. Ctrl+V / Ctrl+Shift+V were the only way to paste.What this changes
Right-click copies the selection if there is one, otherwise pastes — Windows Terminal's default, and already what wmux's own Ctrl+C does with a selection.
vim mouse=a, tmux, htop, opencode)The Shift bypass costs nothing here: xterm's
shouldForceSelectionisshiftKey, so with Shift held xterm sends no mouse report and the gesture is ours.src/renderer/utils/terminal-right-click.ts: a purerightClickAction()decision, plusnormalizeRightClickMode().useTerminal.ts: acontextmenulistener on the xterm container only, so the overlays above it keep their own clicks.contextmenurather than mousedown/auxclick — it fires once per gesture, after xterm has already handled the button (a mouse report, for a tracking app), and Chromium never pastes on it, so there is no second insert to cancel the way Ctrl+V has. xterm's owncontextmenulistener sits on the inner element and does not stop propagation, andrightClickSelectsWordis false on Windows, so the selection we read is the user's.remote.resolvePaste→applyInsertion), so bracketed paste, image/file paste and scp for an ssh pane (Upload pasted and dropped local files in direct SSH panes #195) all apply. Copy trims trailing whitespace like Ctrl+C, because ConPTY pads lines with real spaces (copy bug #102).Right-clickselect — Copy selection, otherwise paste (default), Always paste, Do nothing. English strings only; other locales fall back.terminalPrefs.rightClickis a new field and hydrates as{...DEFAULTS, ...persisted}, so no migration and no rev bump.Tests
tests/unit/terminal-right-click.test.ts: the full truth table (mode × selection × mouse tracking × Shift), the normalizer, the default.npm teston Windows: 296 files / 5154 tests pass, 0 failures (14 skipped).tsc --noEmitpasses fortsconfig.jsonandtsconfig.node.json. ESLint reports no new errors (the pre-existingno-emptyones inuseTerminal.tsare on master too).Manual test (Windows,
npm run dev)vimwith:set mouse=a: bare right-click goes to vim, Shift+right-click pastes.Note
This touches the same regions of
en.ts,settings-slice.ts,TerminalSettings.tsxanduseTerminal.tsas #337 (on-screen bell). Whichever lands second needs a keep-both resolution in those four files — one adds a Bell section, the other a Mouse section; there is no overlapping logic. Happy to rebase this one on top of #337 if you prefer to take that one first.