Skip to content

fix(frontend): wire clipboard copy/paste in XtermTerminal#306

Draft
neversettle17-101 wants to merge 3 commits into
mainfrom
fix-terminal-clipboard-305
Draft

fix(frontend): wire clipboard copy/paste in XtermTerminal#306
neversettle17-101 wants to merge 3 commits into
mainfrom
fix-terminal-clipboard-305

Conversation

@neversettle17-101

Copy link
Copy Markdown
Collaborator

Summary

  • XtermTerminal loaded several xterm.js addons but had no clipboard wiring, so neither the OS Copy command nor plain mouse drag-to-select worked against the zellij-attached PTY (zellij owns SGR mouse tracking, and xterm selection is rendered to canvas, not DOM).
  • Added an attachCustomKeyEventHandler that intercepts Cmd/Ctrl+C (copies term.getSelection() via navigator.clipboard.writeText only when there's an active selection, otherwise lets the event through so Ctrl+C still sends SIGINT) and Cmd/Ctrl+V (reads navigator.clipboard.readText() and forwards via term.paste, rather than relying on xterm's native DOM paste event).
  • Shift+drag for local text selection while zellij owns mouse tracking is xterm's existing default behavior — no change needed there.
  • No new dependency: implemented with the existing @xterm/xterm APIs, no @xterm/addon-clipboard needed.

Test plan

  • pnpm -C frontend typecheck passes
  • pnpm -C frontend test (full renderer suite, including XtermTerminal tests) passes — 140/140
  • Manual: open a session terminal, Shift+drag to select text, Cmd/Ctrl+C to copy, paste into another app
  • Manual: Cmd/Ctrl+V into the terminal pastes clipboard text into the PTY
  • Manual: Ctrl+C with no selection still sends SIGINT to the running process
  • Manual smoke test on Linux/Windows (no native Electron menu there, so this relies entirely on the explicit key handling added here)

Fixes #305

🤖 Generated with Claude Code

zellij owns SGR mouse tracking and xterm's selection model is canvas-only,
so neither the OS Copy command nor plain drag-to-select worked. Intercept
Cmd/Ctrl+C to copy the active selection (falling through when nothing is
selected so Ctrl+C still sends SIGINT) and Cmd/Ctrl+V to paste explicitly
via the clipboard API rather than relying on xterm's native paste event.

Fixes #305

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
neversettle17-101 and others added 2 commits June 19, 2026 20:09
…select text

Cmd+C copy appeared to do nothing because hasSelection() was always false
on macOS: xterm.js only forces local selection over zellij's SGR mouse
tracking on Shift+drag for Windows/Linux — on Mac the override key is
Option/Alt, gated behind macOptionClickForcesSelection which defaults to
false. Without it there was no way to select text on Mac at all.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…clobber

Replace the shared metaKey||ctrlKey copy/paste check with a per-platform
chord table (mac/windows/linux), each easy to extend independently.
macOS keeps Cmd+C/Cmd+V since Ctrl has no PTY meaning there. Windows/Linux
now use Ctrl+Shift+C/V instead of plain Ctrl+C/Ctrl+V, matching GNOME
Terminal/Windows Terminal convention — the previous plain-Ctrl+C check
would have silently swallowed SIGINT whenever there was a stale selection
on those platforms.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@neversettle17-101 neversettle17-101 marked this pull request as draft June 20, 2026 05:32
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.

bug(terminal): cannot copy/paste from the zellij session terminal — no clipboard wiring in XtermTerminal

1 participant