Skip to content

feat(clipboard): Ctrl+C copies selection; Ctrl+V pastes into PTY#121

Merged
MenachemBarak merged 5 commits into
mainfrom
feat/clipboard-copy-paste
Apr 29, 2026
Merged

feat(clipboard): Ctrl+C copies selection; Ctrl+V pastes into PTY#121
MenachemBarak merged 5 commits into
mainfrom
feat/clipboard-copy-paste

Conversation

@MenachemBarak
Copy link
Copy Markdown
Owner

Summary

  • Terminal (xterm.js): Ctrl+C with text selected → copies to clipboard; SIGINT is not sent. Ctrl+V → reads clipboard and sends text to PTY; raw 0x16 is not sent.
  • Transcript pane: explicit Ctrl+C handler ensures copy works in pywebview EdgeWebView2 even when the native clipboard API is restricted.
  • Ctrl+Shift+C / Ctrl+Shift+V remain available as unconditional copy/paste alternatives.

Root cause

xterm.js routes all keystrokes to the PTY via onData. Ctrl+C sent \x03 (SIGINT); Ctrl+V sent \x16. There was no clipboard path. Added term.attachCustomKeyEventHandler() which intercepts these two keys with clipboard semantics before they reach the PTY.

Files changed

File Change
backend/frontend/terminal-pane.jsx attachCustomKeyEventHandler for Ctrl+C (copy) + Ctrl+V (paste)
backend/frontend/transcript.jsx Explicit Ctrl+C keydown handler; execCommand fallback
e2e/tests/feature/clipboard.spec.ts New E2E spec: transcript copy + terminal handler presence

Test plan

  • 274 backend tests pass (known watcher flake excluded)
  • Pre-commit clean
  • CI green
  • Manual: select text in transcript → Ctrl+C → paste elsewhere confirms copy
  • Manual: in active Claude session → select output → Ctrl+C → no interrupt, text in clipboard
  • Manual: in active Claude session → Ctrl+V → pastes clipboard text

🤖 Generated with Claude Code

MenachemBarak and others added 5 commits April 29, 2026 12:07
**Terminal (xterm.js):**
- Ctrl+C with text selected → copies to clipboard; SIGINT is NOT sent
- Ctrl+V → reads clipboard and sends text to PTY; raw 0x16 is NOT sent
- Ctrl+Shift+C / Ctrl+Shift+V still work as before (always-copy / always-paste)
- textarea execCommand fallback when navigator.clipboard is restricted

**Transcript:**
- Ctrl+C on selected text → explicit clipboard write; ensures copy works in
  pywebview EdgeWebView2 even when the native clipboard API is restricted

**Tests:**
- e2e/tests/feature/clipboard.spec.ts covers transcript Ctrl+C and verifies
  xterm terminal handler is wired on open

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…rtions

- Remove dead `__xtermInstances` check that never ran (xterm doesn't expose this)
- Terminal test now verifies canvas renders after "New terminal" click (handler wired)
- Second terminal test types a marker, selects via xterm internal API, Ctrl+C, reads clipboard

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…ht-tab-new-terminal

Previous run failed:
- transcript: [data-testid^="msg-"] found hover-only copy button → timeout;
  fix: use [data-msg-index] which is always present on message divs
- terminal: .xterm-screen canvas not found; fix: use [data-testid^="tile-pane-"]
  (proven pattern from close-pane.spec.ts) + page.getByTestId('right-tab-new-terminal')

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Prior specs may leave a terminal tab active, hiding the transcript pane
(display:none). Explicitly click right-tab-transcript to make pane visible.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…dText

Windows clipboard.readText() returns \r\n even when \n was written.
Strip \r before the toBe assertion so the test passes on Windows CI.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@MenachemBarak MenachemBarak merged commit 2a1d020 into main Apr 29, 2026
15 checks passed
@MenachemBarak MenachemBarak deleted the feat/clipboard-copy-paste branch April 29, 2026 10:35
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