Skip to content

fix(desktop): match VS Code terminal clipboard handling (originally by @AytuncYildizli)#3415

Merged
Kitenite merged 3 commits into
mainfrom
tui-cmd-shortcuts
Apr 13, 2026
Merged

fix(desktop): match VS Code terminal clipboard handling (originally by @AytuncYildizli)#3415
Kitenite merged 3 commits into
mainfrom
tui-cmd-shortcuts

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Apr 13, 2026

Reported and fixed from: #3407

Summary

  • forward the v1 terminal clipboard chords the same way VS Code does so xterm's kitty keyboard handling does not swallow host copy and paste
  • add macOS terminal select-all (Cmd+A) to match VS Code's terminal action behavior
  • tighten the platform guard so Linux fallback chords do not leak onto macOS
  • replace the verbose shortcut tests with a compact boundary-focused matrix

Root Cause

#3390 changed the v1 terminal so unregistered chords fall through to the PTY. That fixed TUI shortcut forwarding in general, but it also let xterm consume host clipboard chords as CSI-u input before Electron/browser copy-paste handling could run. On macOS this broke Cmd+C and Cmd+V; the follow-up implementation also needed an explicit guard so Linux fallback bindings like Ctrl+Shift+V and Shift+Insert would not be intercepted on macOS.

Behavior

  • macOS: Cmd+C copies only when there is a terminal selection, Cmd+V pastes, Cmd+A selects all
  • Windows: Ctrl+V, Ctrl+Shift+V, and copy chords with a selection bubble to the host
  • Linux: Ctrl+Shift+C, Ctrl+Shift+V, and Shift+Insert follow VS Code's terminal bindings
  • terminal-reserved PTY chords still go to xterm when they should

Validation

  • bun test apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/clipboardShortcuts.test.ts
  • bun run typecheck --filter=@superset/desktop
  • bunx biome check apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/helpers.ts apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/clipboardShortcuts.ts apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/clipboardShortcuts.test.ts

Summary by CodeRabbit

  • Tests

    • Added comprehensive test coverage for clipboard shortcuts across macOS, Windows, and Linux platforms.
  • New Features

    • Enhanced clipboard shortcut handling in the terminal, ensuring consistent copy, paste, and select-all functionality across all operating systems.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d7100f12-4c22-4462-b65d-89b475bc251d

📥 Commits

Reviewing files that changed from the base of the PR and between 9b21b49 and 91177e8.

📒 Files selected for processing (3)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/clipboardShortcuts.test.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/clipboardShortcuts.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/helpers.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/clipboardShortcuts.test.ts

📝 Walkthrough

Walkthrough

Adds platform- and selection-aware clipboard shortcut detection and select-all handling for the terminal. New helpers determine when clipboard shortcuts should bubble to the host; the keyboard handler uses them to short-circuit xterm consumption. Tests cover macOS, Windows, and Linux variants.

Changes

Cohort / File(s) Summary
Clipboard shortcut logic & tests
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/clipboardShortcuts.ts, apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/clipboardShortcuts.test.ts
Added ClipboardShortcutEvent and ClipboardShortcutOptions interfaces, shouldSelectAllShortcut() and shouldBubbleClipboardShortcut() functions implementing platform/selection rules for copy/paste/select-all, plus comprehensive Bun tests covering macOS/Windows/Linux chord matrices.
Keyboard handler integration
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/helpers.ts
Integrated select-all and clipboard-bubble checks into setupKeyboardHandler before terminal-reserved chord handling; matched shortcuts prevent xterm from consuming the event and allow bubbling.

Sequence Diagram(s)

sequenceDiagram
    participant Keyboard as KeyboardEvent
    participant Handler as setupKeyboardHandler
    participant Shortcuts as shouldBubbleClipboardShortcut / shouldSelectAllShortcut
    participant XTerm as xterm
    participant Host as Host/Window

    Keyboard->>Handler: keydown with modifiers
    Handler->>Shortcuts: evaluate event + platform + selection
    alt select-all matched
        Shortcuts-->>Handler: select-all
        Handler->>XTerm: call xterm.selectAll() and preventDefault
        Handler-->>Host: stop further bubbling
    else clipboard shortcut matched
        Shortcuts-->>Handler: bubble=true
        Handler-->>Host: allow bubble (return false to stop xterm)
        Host->>Host: handle copy/paste
    else no match
        Shortcuts-->>Handler: bubble=false
        Handler->>XTerm: continue terminal-reserved processing
        XTerm->>XTerm: handle event
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Poem

🐰 I nibble keys and skip the fence,
Cmd or Ctrl I sense the sense,
I hop selections, paste with glee,
Across Mac, Win, and Linux tree,
Shortcuts bubble — rabbit jubilee! 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main objective: matching VS Code's terminal clipboard handling behavior, which is the primary goal of this PR.
Description check ✅ Passed The PR description provides a comprehensive summary, root cause analysis, detailed behavior changes, and validation steps, exceeding the template requirements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tui-cmd-shortcuts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 13, 2026

Greptile Summary

This PR extracts clipboard shortcut forwarding logic into a dedicated clipboardShortcuts.ts module and integrates it into the xterm keyboard handler in helpers.ts. The goal is to ensure that host copy/paste shortcuts (e.g. Cmd+V on macOS, Ctrl+V on Windows) are handled by Electron before xterm's kitty keyboard protocol (CSI-u) can rewrite them into escape sequences — preventing TUI apps from swallowing clipboard chords.

Key changes:

  • New shouldBubbleClipboardShortcut function mirrors VS Code's per-platform terminal clipboard bindings across macOS, Windows, and Linux.
  • The function is called early in setupKeyboardHandler (before isTerminalReservedEvent) so clipboard events bypass xterm and propagate to the host.
  • A comprehensive unit test suite covers the happy paths for all three platforms.

Issue found:

  • The Linux-style fallback (Ctrl+Shift+V, Shift+Insert, Ctrl+Shift+C with selection) is not guarded by !isMac, so it runs on macOS when the Cmd-key branch doesn't match. A macOS user pressing Ctrl+Shift+V or a TUI app expecting to receive Shift+Insert on macOS would have the keystroke silently intercepted and consumed by the host instead of reaching the PTY. The fix is a one-line guard (if (!isMac)) around the fallback return.

Confidence Score: 3/5

Safe to merge on Windows/Linux; macOS has a platform-guard bug that could silently drop keystrokes intended for TUI apps.

The core feature is well-designed and the integration point in helpers.ts is correct. However, the missing !isMac guard on the Linux fallback is a real logic error: on macOS, Ctrl+Shift+V, Shift+Insert, and Ctrl+Shift+C (with a selection) will be bubbled to Electron instead of reaching the PTY. Any TUI application on macOS that uses those key sequences as internal shortcuts will silently break. The fix is a one-liner, so the score reflects a targeted fix remaining before merge.

clipboardShortcuts.ts (the fallback return) and clipboardShortcuts.test.ts (missing macOS boundary assertions)

Important Files Changed

Filename Overview
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/clipboardShortcuts.ts New utility that mirrors VS Code clipboard shortcuts — contains a logic bug where the Linux-style fallback applies to macOS, intercepting non-standard key combos like Ctrl+Shift+V on Mac before they reach the PTY.
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/clipboardShortcuts.test.ts Good test coverage for the happy path; missing boundary tests for macOS with Linux-style shortcuts and Linux Ctrl+Shift+C without selection.
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/helpers.ts Integration of shouldBubbleClipboardShortcut is correctly placed before isTerminalReservedEvent and properly returns false from xterm's key handler to let the host handle clipboard operations.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[KeyboardEvent in xterm handler] --> B{shouldBubbleClipboardShortcut?}
    B -->|true - clipboard shortcut| C[return false\nhost handles copy/paste]
    B -->|false - not clipboard| D{isTerminalReservedEvent?\nCtrl+C/D/Z/S/Q}
    D -->|true| E[return true\nxterm sends to PTY]
    D -->|false| F{Registered app hotkey?}
    F -->|yes| G[return false\napp handles hotkey]
    F -->|no| E

    subgraph shouldBubbleClipboardShortcut logic
        H{isMac and onlyMeta?} -->|yes| I{KeyV or KeyC+selection?}
        I -->|yes| J[return true]
        I -->|no| K[return false]
        H -->|no| L{isWindows?}
        L -->|yes| M{KeyV+Ctrl or CtrlShift or KeyC+selection+Ctrl/CtrlShift?}
        M -->|yes| J
        M -->|no| K
        L -->|no - Linux fallback also runs on macOS| N{KeyV+CtrlShift or Insert+Shift or KeyC+CtrlShift+selection?}
        N -->|yes| J
        N -->|no| K
    end
Loading

Reviews (1): Last reviewed commit: "Handle more keyboard shortcuts" | Re-trigger Greptile

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 13, 2026

🚀 Preview Deployment

🔗 Preview Links

Service Status Link
Neon Database (Neon) View Branch
Fly.io Electric (Fly.io) View App
Vercel API (Vercel) Open Preview
Vercel Web (Vercel) Open Preview
Vercel Marketing (Vercel) Open Preview
Vercel Admin (Vercel) Open Preview
Vercel Docs (Vercel) Open Preview

Preview updates automatically with new commits

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/clipboardShortcuts.ts">

<violation number="1" location="apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/clipboardShortcuts.ts:50">
P2: The final return block is reachable on macOS when the key event doesn't include `Cmd` (e.g. `Ctrl+Shift+V`, `Shift+Insert`). The `isMac && onlyMeta` guard on line 35 only early-returns for `Cmd`-based shortcuts; any other modifier combination on macOS falls through to this Linux-specific block. This causes Linux clipboard bindings to incorrectly fire on macOS, intercepting shortcuts that should reach the PTY.

Wrap this block in `if (!isMac)` and add a `return false` fallback:</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@Kitenite Kitenite changed the title Tui cmd shortcuts forwarding fix(desktop): match VS Code terminal clipboard handling Apr 13, 2026
@Kitenite Kitenite merged commit d656b7e into main Apr 13, 2026
14 checks passed
@Kitenite Kitenite changed the title fix(desktop): match VS Code terminal clipboard handling fix(desktop): match VS Code terminal clipboard handling (originally by @AytuncYildizli) Apr 13, 2026
@Kitenite Kitenite deleted the tui-cmd-shortcuts branch April 13, 2026 16:35
MocA-Love pushed a commit to MocA-Love/superset that referenced this pull request Apr 14, 2026
…3415)

* Fix code TUI copy

* Handle more keyboard shortcuts

* fix(desktop): match VS Code terminal clipboard handling
MocA-Love pushed a commit to MocA-Love/superset that referenced this pull request Apr 14, 2026
All 9 upstream commits have been individually cherry-picked via PR#159~#163:

| Upstream | Our PR | Description |
|---|---|---|
| d656b7e (superset-sh#3415) | #159 (PR#1) | terminal clipboard handling |
| 31fcf19 (superset-sh#3416) | #162 (PR#4) | v1 split pane startup sizing fix |
| 039edf2 (superset-sh#3403) | #161 (PR#3) | Cmd+Alt+Arrow spatial pane focus |
| b18a00c (superset-sh#3421) | #159 (PR#1) | v2 right sidebar toggle reactive |
| 3dd1de2 (superset-sh#3420) | #161 (PR#3) | v2 diff viewer + tab title resolution |
| b42a114 (superset-sh#3418) | #159 (PR#1) | CodeMirror hotkey enablement |
| c925f4d (superset-sh#3422) | #160 (PR#2) | unbound defaults + restore prev/next tab/workspace |
| bb12c09 (superset-sh#3419) | #163 (PR#5) | version bump 1.5.3 |
| 47efa73 (superset-sh#3432) | #159 (PR#1) | pending/update-required error selectable |

Fork-specific features preserved:
- auto-updater (IS_FORK, GitHub Releases API)
- QuitMode/cleanupMainWindowResources lifecycle
- GitHubSyncService, SpreadsheetViewer
- BROWSER_RELOAD / BROWSER_HARD_RELOAD / SEARCH_IN_FILES hotkeys
- HotkeyCategory "Browser"
- v1 deep-link navigation (useSearch/WorkspaceSearchParams)
- v1 tRPC-based PREV/NEXT_WORKSPACE handlers
- v1 CLOSE_TERMINAL/CLOSE_TAB hotkey handlers
- v2 extra state (rightSidebarOpenViewWidth, showPresetsBar)
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