Match Linux terminal copy/paste behavior#15
Conversation
Route terminal clipboard access through Electron so Linux can use both the normal clipboard and the X11/selection buffer. This avoids relying on browser-only clipboard APIs for behaviors that users expect to match native terminal emulators under Linux and WSL2. Update TerminalView to follow the Linux workflow you validated in testing: left drag selects, right click copies the current selection and clears it, and a subsequent right click pastes when no selection is active. Keep middle-click paste from the selection buffer and preserve keyboard copy/paste, including Ctrl+Insert and Shift+Insert.
|
Thank you very much for this and sorry for the late reply. Somehow I wasn't receiving notifications for PRs opened here. Could you have a look at the conflicts please? |
There was a problem hiding this comment.
Code Review
Overall: Well-structured PR that correctly solves a real Linux clipboard limitation. Routing clipboard through Electron IPC is the right call — browser navigator.clipboard can't access the X11 selection buffer. Clean implementation, proper cleanup, good test coverage on the backend.
Important
1. Needs rebase — merge conflict on register.ts line 1
Main now imports Notification from electron (from 587fde6). This PR changes the same line, so it will conflict. Resolved import should be:
import { ipcMain, dialog, shell, app, BrowserWindow, Notification, clipboard } from 'electron';2. Incomplete test mocks in register.test.ts
After rebase, the electron mock will need Notification. Also missing from mocks: getAllFileDiffs/getAllFileDiffsFromBranch in git.js, and plans.js exports stopAllPlanWatchers but register.ts imports stopPlanWatcher (singular) + readPlanForWorktree.
3. pasteClipboard silently swallows errors
.catch(() => {});A console.warn would help debug clipboard failures across Linux DEs (GNOME, KDE, Wayland, X11).
4. Unrelated test removal in pty.test.ts
The "bare command found in PATH" test deletion is unrelated to clipboard work — should be a separate commit.
5. ClipboardWrite with target: 'selection' on non-Linux writes nothing
if (target !== 'selection') clipboard.writeText(args.text); // skipped
if ((target === 'selection' || target === 'both') && process.platform === 'linux') { // skipped on macOSDead path today (frontend only sends 'both' or 'clipboard'), but worth either falling back to the default clipboard or throwing on unsupported platform+target combos.
Minor
- The
requestAnimationFrameinhandleContextMenucould use a brief comment explaining why the deferral is needed (letting browser finalize selection after right-click). - Missing test cases:
ClipboardWritewith explicit'clipboard'target,ClipboardReadwith no target,ClipboardWritewith'selection'on non-Linux.
Summary