xterm.js icon indicating copy to clipboard operation
xterm.js copied to clipboard

Kitty keyboard mode swallows Shift+Insert paste (and Ctrl+Insert copy)

Open y5ez3g opened this issue 3 weeks ago • 1 comments

With the kitty keyboard protocol active, Shift+Insert and Ctrl+Insert are sent to the program as CSI 2;2~ and CSI 2;5~, and the keydown is cancelled. The legacy encoder deliberately leaves both keys alone so the browser performs its native paste and copy:

// src/common/input/Keyboard.ts
case 45:
  // insert
  if (!ev.shiftKey && !ev.ctrlKey) {
    // <Ctrl> or <Shift> + <Insert> are used to
    // copy-paste on some systems.
    result.key = C0.ESC + '[2~';
  }

KittyKeyboard has no such exception. Insert is in _csiTildeKeys, so it is always encoded, with cancel: true.

Both encoders from master (f70764dd3d), given a keydown with key: 'Insert', keyCode: 45:

Key evaluateKeyboardEvent (legacy) KittyKeyboard.evaluate, flags 5
Shift+Insert { key: undefined, cancel: false } { key: '\x1b[2;2~', cancel: true }
Ctrl+Insert { key: undefined, cancel: false } { key: '\x1b[2;5~', cancel: true }

Details

  • Browser and browser version: VS Code 1.145.0 (Electron)
  • OS version: Windows, where Shift+Insert is a system paste shortcut
  • xterm.js version: master f70764dd3d; 6.1.0-beta.304 as bundled in VS Code 1.145.0

VS Code enables vtExtensions.kittyKeyboard by default (terminal.integrated.enableKittyKeyboardProtocol), and its terminal binds no paste to Shift+Insert on Windows, so the key reaches xterm.js. Programs such as OpenCode (flags 5) and Claude Code (since 2.1.269) turn the protocol on, after which Shift+Insert no longer pastes. Dictation tools are hit hardest: Wispr Flow pastes with Shift+Insert whenever VS Code is in front, so dictated text is silently lost. anthropics/claude-code#93782 has user reports with this signature; setting enableKittyKeyboardProtocol to false restores paste.

VS Code already works around the same gap for Meta keys in terminalInstance.ts: "The (non-kitty) traditional xterm.js handler already skips Meta keys so they bubble up naturally, but the kitty handler does not."

Steps to reproduce

  1. On Windows, copy some text to the clipboard.
  2. In a VS Code terminal (Git Bash), turn the protocol on and echo input: printf '\e[>1u'; cat -v
  3. Press Shift+Insert.

Expected: the clipboard text is pasted, as it is with the protocol off. Actual, from the code path above: ^[[2;2~ is printed and nothing is pasted. This was traced in code and with the encoder output above, not run on a Windows machine.

Suggested fix

Give the kitty encoder the legacy exception: with Shift or Ctrl held, Insert produces no key and the event is not cancelled, so the browser's paste and copy run. kitty itself treats Shift+Insert as a terminal shortcut (paste_from_selection) and does not report it to the program.

y5ez3g avatar Nov 11 '26 19:11 y5ez3g

I can reproduce this at the encoder level: with the same keydown (key: 'Insert', keyCode: 45, shiftKey: true), the legacy encoder returns { key: undefined, cancel: false } while KittyKeyboard.evaluate returns { key: '\x1b[2;2~', cancel: true }.

I'm taking this. The fix adds the same Shift/Ctrl+Insert exception to KittyKeyboard.evaluate (no key and no cancel, for any kitty flags) plus unit tests in KittyKeyboard.test.ts. PR follows.

mccalpink avatar Nov 12 '26 16:11 mccalpink