mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
With the kitty keyboard protocol active, these function keys were not
recognized:
- F1, F2 and F4 arrive as `CSI P`/`Q`/`S`, or as `CSI 1;<mod> P/Q/S`.
- Any F-key pressed with a modifier, e.g. `CSI 15;5~` for Ctrl+F5.
`matchesKey` returned false whenever a modifier was set and only
compared against the legacy sequences. `parseKittySequence` did not know
any F-key forms. So shortcuts bound to keys like `f1` or `ctrl+f5` never
fired.
Separately, F13–F35 (and other kitty functional keys) arrive as CSI-u
codepoints in the Private Use Area. `decodeKittyPrintable` returned them
as text, so the editor inserted invisible U+E020+ characters into the
prompt.
Changes in `packages/tui/src/keys.ts`:
- Add F1–F12 internal codepoints. Map `~` numbers 11–15, 17–21, 23 and
24 to them.
- Parse the `CSI [1;mod[:event]] P/Q/S` form. F3 is left out because
`CSI 1;<n>R` collides with cursor position reports, so kitty sends F3 as
`CSI 13~`.
- Let the `f1`…`f12` cases in `matchesKey` fall back to
`matchesKittySequence` so modifiers work. Name the keys in `parseKey`
output.
- Make `isKeyRelease` and `isKeyRepeat` recognize `:3`/`:2` events on
P/Q/S, so F1/F2/F4 releases don't trigger shortcuts a second time.
- `decodeKittyPrintable` now rejects the kitty functional-key PUA range
(57344–63743). Keypad keys are normalized to ASCII first, so they still
decode.
Testing:
- Added tests in `packages/tui/test/keys.test.ts`. They cover kitty
F1–F12 with and without modifiers, F3 not being confused with a cursor
position report, release and repeat detection, and F13+ not decoding as
text. Two of the new tests fail without the change; all pass with it.
- Ran `npm test` in `packages/tui` and `npm run check`; both pass.
- Before the change: `parseKey("\x1b[P")` and `parseKey("\x1b[1;5P")`
returned `undefined`, `matchesKey("\x1b[15;5~", "ctrl+f5")` returned
false, and `decodePrintableKey("\x1b[57376u")` returned `"\ue020"`.
- After the change: these give `f1`, `ctrl+f1`, true and `undefined`.
Fixes #11419
Fixes #11345
Requested by @badlogic
Co-authored-by: triagent <triagent@localhost>
|
||
|---|---|---|
| .. | ||
| fixtures | ||
| alt-screen-large-transcript-bench.ts | ||
| autocomplete-skill-slash.test.ts | ||
| autocomplete.test.ts | ||
| bug-regression-isimageline-startswith-bug.test.ts | ||
| chat-simple.ts | ||
| colors.test.ts | ||
| editor-history-keybindings.test.ts | ||
| editor.test.ts | ||
| exit-restore.test.ts | ||
| fuzzy.test.ts | ||
| image-test.ts | ||
| input.test.ts | ||
| key-tester.ts | ||
| keybindings.test.ts | ||
| keys.test.ts | ||
| latex.test.ts | ||
| layout.test.ts | ||
| markdown.test.ts | ||
| mouse-components.test.ts | ||
| native-clipboard-linux.test.ts | ||
| native-module-path.test.ts | ||
| native-platform.test.ts | ||
| overlay-non-capturing.test.ts | ||
| overlay-options.test.ts | ||
| overlay-short-content.test.ts | ||
| program-status.test.ts | ||
| regression-overlay-cjk-boundary.test.ts | ||
| regression-regional-indicator-width.test.ts | ||
| regression-sigwinch-kill-eacces.test.ts | ||
| regression-slice-by-column-ansi-order.test.ts | ||
| render-churn-bench.ts | ||
| select-list.test.ts | ||
| settings-list.test.ts | ||
| stdin-buffer.test.ts | ||
| tab-width.test.ts | ||
| terminal-colors.test.ts | ||
| terminal-image.test.ts | ||
| terminal.test.ts | ||
| test-themes.ts | ||
| truncate-to-width.test.ts | ||
| truncated-text.test.ts | ||
| tui-alt-screen.test.ts | ||
| tui-cell-size-input.test.ts | ||
| tui-overlay-style-leak.test.ts | ||
| tui-render.test.ts | ||
| tui-shrink.test.ts | ||
| viewport-overwrite-repro.ts | ||
| virtual-terminal.ts | ||
| visible-width.test.ts | ||
| wheel-scroll.test.ts | ||
| word-navigation.test.ts | ||
| wrap-ansi.test.ts | ||