feat(cli): support literal character keybindings and extended Kitty protocol keys (#21972)

This commit is contained in:
Tommaso Sciortino
2026-03-11 04:49:20 +00:00
committed by GitHub
parent f8ad3a200a
commit 075e0b1a81
4 changed files with 97 additions and 28 deletions
@@ -97,13 +97,6 @@ describe('KeyBinding', () => {
'Invalid keybinding key: "ctlr+a" in "ctlr+a"',
);
});
it('should throw an error for literal "+" as key (must use "=")', () => {
// VS Code style peeling logic results in "+" as the remains
expect(() => new KeyBinding('alt++')).toThrow(
'Invalid keybinding key: "+" in "alt++"',
);
});
});
});
+8 -6
View File
@@ -110,10 +110,8 @@ export enum Command {
* Data-driven key binding structure for user configuration
*/
export class KeyBinding {
private static readonly VALID_KEYS = new Set([
...'abcdefghijklmnopqrstuvwxyz0123456789', // Letters & Numbers
..."`-=[]\\;',./", // Punctuation
...Array.from({ length: 19 }, (_, i) => `f${i + 1}`), // Function Keys
private static readonly VALID_LONG_KEYS = new Set([
...Array.from({ length: 35 }, (_, i) => `f${i + 1}`), // Function Keys
...Array.from({ length: 10 }, (_, i) => `numpad${i}`), // Numpad Numbers
// Navigation & Actions
'left',
@@ -130,6 +128,7 @@ export class KeyBinding {
'space',
'backspace',
'delete',
'clear',
'pausebreak',
'capslock',
'insert',
@@ -193,8 +192,11 @@ export class KeyBinding {
const key = remains;
if (!KeyBinding.VALID_KEYS.has(key)) {
throw new Error(`Invalid keybinding key: "${key}" in "${pattern}"`);
if ([...key].length !== 1 && !KeyBinding.VALID_LONG_KEYS.has(key)) {
throw new Error(
`Invalid keybinding key: "${key}" in "${pattern}".` +
` Must be a single character or one of: ${[...KeyBinding.VALID_LONG_KEYS].join(', ')}`,
);
}
this.key = key;