Skip to content
Closed
16 changes: 16 additions & 0 deletions packages/cli/src/ui/contexts/KeypressContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,17 @@ describe('KeypressContext', () => {
sequence: '\x1b[32;5u',
},
},
// Raw single-byte backspace sequences (no keyboard protocol)
{
name: 'Backspace (raw \\b = 0x08)',
inputSequence: '\b',
expected: { name: 'backspace', alt: false, ctrl: false, cmd: false },
},
{
name: 'Backspace (raw \\x7f = 0x7F)',
inputSequence: '\x7f',
expected: { name: 'backspace', alt: false, ctrl: false, cmd: false },
},
])(
'should recognize $name in kitty protocol',
async ({ inputSequence, expected }) => {
Expand Down Expand Up @@ -695,6 +706,11 @@ describe('KeypressContext', () => {
sequence: `\x1b[27;6;9~`,
expected: { name: 'tab', shift: true, ctrl: true },
},
// ModifyOtherKeys: Ctrl+Backspace (code 8 = backspace)
{
sequence: `\x1b[27;5;8~`,
expected: { name: 'backspace', ctrl: true },
},
// Unicode CJK (Kitty/modifyOtherKeys scalar values)
{
sequence: '\x1b[44032u',
Expand Down
10 changes: 8 additions & 2 deletions packages/cli/src/ui/contexts/KeypressContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const KITTY_CODE_MAP: Record<number, { name: string; sequence?: string }> = {
3: { name: 'delete' },
5: { name: 'pageup' },
6: { name: 'pagedown' },
8: { name: 'backspace' },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Improvement (Minor):
Please add a test case for this new modifyOtherKeys fallback sequence (\x1b[27;5;8~) in packages/cli/src/ui/contexts/KeypressContext.test.tsx. There is an existing block called "Parameterized functional keys" where this would fit perfectly.

9: { name: 'tab' },
13: { name: 'enter' },
14: { name: 'up' },
Expand Down Expand Up @@ -652,8 +653,13 @@ function* emitKeys(
// tab
name = 'tab';
alt = escaped;
} else if (ch === '\b' || ch === '\x7f') {
// backspace or ctrl+h
} else if (ch === '\b') {
// backspace (0x08 - some terminals send this for ctrl+h/ctrl+backspace)
// Note: no ctrl=true heuristic is applied since raw \b is ambiguous
name = 'backspace';
alt = escaped;
} else if (ch === '\x7f') {
// backspace (0x7F - DEL, used as backspace on most modern terminals)
name = 'backspace';
alt = escaped;
} else if (ch === ESC) {
Expand Down