Skip to content

fix(terminal): restore copy and paste on Linux and Windows - #91

Merged
SametKUM merged 4 commits into
mainfrom
fix/terminal-clipboard
Sep 5, 2026
Merged

SametKUM merged 4 commits into
mainfrom
fix/terminal-clipboard

Conversation

@SametKUM

@SametKUM SametKUM commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Summary

Copy and paste never worked in Klustr's terminals on Linux and Windows — Exec, Node shell, the terminal drawer, and copying from the Logs viewers. Reported in discussion #90.

Root cause. On macOS the Wails Edit menu turns ⌘C / ⌘V into native clipboard commands and xterm.js leaves ⌘-chords alone, so it always worked there. Linux (WebKit2GTK) and Windows (WebView2) have no such menu; xterm.js maps Ctrl+C / Ctrl+V to the ^C / ^V control bytes and calls preventDefault(), so the webview never fires a copy / paste event and xterm's own clipboard handlers never run. Right-click was dead as well: release builds don't enable the webview's default context menu.

Fix.

  • xtermClipboard.tsattachCustomKeyEventHandler binds the terminal-convention chords on Linux/Windows: Ctrl+Shift+C / Ctrl+Insert copy, Ctrl+Shift+V / Shift+Insert paste, and a plain Ctrl+C copies while text is selected (SIGINT otherwise, matching Windows Terminal and VS Code). macOS is untouched — the matcher returns null there.
  • Clipboard I/O goes through the Wails runtime (ClipboardGetText / ClipboardSetText) first: WebKitGTK has no navigator.clipboard.readText and WebView2 permission-gates it. Paste uses term.paste() so bracketed paste and newline normalisation survive.
  • TerminalContextMenu.tsx — right-click Copy / Paste / Select all on every terminal surface (copy-only in the Logs viewers), focus handed back to xterm on close.
  • Cheatsheet entries and guide docs.

Verification

  • npm test (188 passing, 7 new for the chord matcher), npm run lint, npm run typecheck, npm run build.
  • Manual on Linux (wails build -tags webkit2_41, WebKitGTK 2.52): Exec, Node shell, drawer and Logs — chords, selection-aware Ctrl+C followed by SIGINT, right-click menu, multi-line paste into bash and vim; no regressions on Ctrl+D/L/R, arrows, Tab.
  • macOS: keyboard path unchanged by construction; the right-click menu is new.
  • Windows: same code path (Wails disables WebView2 browser accelerator keys and implements the clipboard runtime); confirmation from a Windows build requested in Cut and paste to/from exec shell #90.

Refs #90

🤖 Generated with Claude Code

SametKUM and others added 4 commits September 5, 2026 21:04
On macOS the Wails Edit menu turns ⌘C / ⌘V into native clipboard commands
and xterm.js leaves ⌘-chords alone, so copy and paste always worked there.
Linux (WebKit2GTK) and Windows (WebView2) have no such menu; xterm.js maps
Ctrl+C / Ctrl+V to the ^C / ^V control bytes and cancels the browser
default, so the webview never fires a copy or paste event and xterm's own
clipboard handlers never run.

Bind the terminal-convention chords through attachCustomKeyEventHandler:
Ctrl+Shift+C / Ctrl+Insert copy, Ctrl+Shift+V / Shift+Insert paste, and a
plain Ctrl+C copies while text is selected (SIGINT otherwise, matching
Windows Terminal and VS Code). macOS keeps its native path untouched.

Clipboard I/O goes through the Wails runtime first — WebKitGTK has no
navigator.clipboard.readText and WebView2 permission-gates it — and paste
uses term.paste() so bracketed paste and newline normalisation survive.
Wired into Exec, Node shell, the terminal drawer and (copy only) both Logs
viewers.

Refs: #90

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Release builds do not enable the webview's default context menu, so
right-clicking a terminal did nothing and mouse-only users on Linux and
Windows had no way to paste at all. Wrap every xterm host in a Radix
context menu with Copy / Paste / Select all (copy-only in the Logs viewers)
that reuses the clipboard helpers and hands focus back to xterm on close.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@SametKUM
SametKUM force-pushed the fix/terminal-clipboard branch from 239c73f to baae902 Compare September 5, 2026 18:04
@SametKUM
SametKUM merged commit ece43ff into main Sep 5, 2026
9 checks passed
@SametKUM
SametKUM deleted the fix/terminal-clipboard branch September 5, 2026 18:10
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.

1 participant