8000 feat(terminal): right-click copies the selection or pastes by SriSatyaLokesh · Pull Request #338 · amirlehmam/wmux · GitHub
[go: up one dir, main page]

Skip to content

feat(terminal): right-click copies the selection or pastes - #338

Merged
amirlehmam merged 1 commit into
amirlehmam:masterfrom
SriSatyaLokesh:pr/right-click-upstream
Oct 23, 2026
Merged

amirlehmam merged 1 commit into
amirlehmam:masterfrom
SriSatyaLokesh:pr/right-click-upstream

Conversation

@SriSatyaLokesh
Copy link
Copy Markdown
Contributor

Closes #336

Problem

Right-click inside a terminal pane did nothing. No contextmenu handler 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.

Bare right-click With Shift
Nothing tracking the mouse copy selection, else paste same
App tracking the mouse (vim mouse=a, tmux, htop, opencode) goes to the app copy/paste

The Shift bypass costs nothing here: xterm's shouldForceSelection is shiftKey, so with Shift held xterm sends no mouse report and the gesture is ours.

  • src/renderer/utils/terminal-right-click.ts: a pure rightClickAction() decision, plus normalizeRightClickMode().
  • useTerminal.ts: a contextmenu listener on the xterm container only, so the overlays above it keep their own clicks. contextmenu rather 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 own contextmenu listener sits on the inner element and does not stop propagation, and rightClickSelectsWord is false on Windows, so the selection we read is the user's.
  • Paste goes through the same resolver as Ctrl+V (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).
  • Settings → Terminal: a new Mouse section with a Right-click select — Copy selection, otherwise paste (default), Always paste, Do nothing. English strings only; other locales fall back.

terminalPrefs.rightClick is 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.
  • Full npm test on Windows: 296 files / 5154 tests pass, 0 failures (14 skipped).
  • tsc --noEmit passes for tsconfig.json and tsconfig.node.json. ESLint reports no new errors (the pre-existing no-empty ones in useTerminal.ts are on master too).

Manual test (Windows, npm run dev)

  • Copy a command, right-click in a pwsh / bash / cmd pane: pastes at the prompt, pane keeps keyboard focus, nothing executes.
  • Select text, right-click: selection copied and cleared, nothing pasted.
  • Multi-line paste into a bracketed-paste shell: one block, not executed.
  • vim with :set mouse=a: bare right-click goes to vim, Shift+right-click pastes.
  • Right-click set to Do nothing: inert immediately, no restart.

Note

This touches the same regions of en.ts, settings-slice.ts, TerminalSettings.tsx and useTerminal.ts as #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.

…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.
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.

Right-click in a terminal pane does nothing — it should copy the selection / paste the clipboard

2 participants

0