Skip to content

Commit 048bf6e

Browse files
authored
fix(cli-ui): revert backspace handling to fix Windows regression (#25941)
1 parent ed469e4 commit 048bf6e

4 files changed

Lines changed: 5 additions & 101 deletions

File tree

packages/cli/src/ui/components/SettingsDialog.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ enum TerminalKeys {
4444
LEFT_ARROW = '\u001B[D',
4545
RIGHT_ARROW = '\u001B[C',
4646
ESCAPE = '\u001B',
47-
BACKSPACE = '\x7f',
47+
BACKSPACE = '\u0008',
4848
CTRL_P = '\u0010',
4949
CTRL_N = '\u000E',
5050
}

packages/cli/src/ui/components/shared/BaseSettingsDialog.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ enum TerminalKeys {
2424
LEFT_ARROW = '\u001B[D',
2525
RIGHT_ARROW = '\u001B[C',
2626
ESCAPE = '\u001B',
27-
BACKSPACE = '\x7f',
27+
BACKSPACE = '\u0008',
2828
CTRL_L = '\u000C',
2929
}
3030

packages/cli/src/ui/contexts/KeypressContext.test.tsx

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,7 @@ import { act } from 'react';
99
import { renderHookWithProviders } from '../../test-utils/render.js';
1010
import { createMockSettings } from '../../test-utils/settings.js';
1111
import { waitFor } from '../../test-utils/async.js';
12-
import type { Mock } from 'vitest';
13-
import {
14-
vi,
15-
afterAll,
16-
beforeAll,
17-
describe,
18-
it,
19-
expect,
20-
beforeEach,
21-
afterEach,
22-
} from 'vitest';
12+
import { vi, afterAll, beforeAll, type Mock } from 'vitest';
2313
import {
2414
useKeypressContext,
2515
ESC_TIMEOUT,
@@ -441,80 +431,6 @@ describe('KeypressContext', () => {
441431
);
442432
});
443433

444-
describe('Windows Terminal Backspace handling', () => {
445-
afterEach(() => {
446-
vi.unstubAllEnvs();
447-
});
448-
449-
it('should NOT treat \\b as ctrl when WT_SESSION is NOT present and OS is not Windows_NT', async () => {
450-
vi.stubEnv('WT_SESSION', '');
451-
vi.stubEnv('OS', 'Linux');
452-
const { keyHandler } = await setupKeypressTest();
453-
454-
act(() => {
455-
stdin.write('\b');
456-
});
457-
458-
expect(keyHandler).toHaveBeenCalledWith(
459-
expect.objectContaining({
460-
name: 'backspace',
461-
ctrl: false,
462-
}),
463-
);
464-
});
465-
466-
it('should treat \\b as ctrl when WT_SESSION IS present (even if not Windows_NT)', async () => {
467-
vi.stubEnv('WT_SESSION', 'some-id');
468-
vi.stubEnv('OS', 'Linux');
469-
const { keyHandler } = await setupKeypressTest();
470-
471-
act(() => {
472-
stdin.write('\b');
473-
});
474-
475-
expect(keyHandler).toHaveBeenCalledWith(
476-
expect.objectContaining({
477-
name: 'backspace',
478-
ctrl: true,
479-
}),
480-
);
481-
});
482-
483-
it('should treat \\b as ctrl when OS is Windows_NT', async () => {
484-
vi.stubEnv('WT_SESSION', '');
485-
vi.stubEnv('OS', 'Windows_NT');
486-
const { keyHandler } = await setupKeypressTest();
487-
488-
act(() => {
489-
stdin.write('\b');
490-
});
491-
492-
expect(keyHandler).toHaveBeenCalledWith(
493-
expect.objectContaining({
494-
name: 'backspace',
495-
ctrl: true,
496-
}),
497-
);
498-
});
499-
500-
it('should treat \\x7f as regular backspace regardless of WT_SESSION or OS', async () => {
501-
vi.stubEnv('WT_SESSION', 'some-id');
502-
vi.stubEnv('OS', 'Windows_NT');
503-
const { keyHandler } = await setupKeypressTest();
504-
505-
act(() => {
506-
stdin.write('\x7f');
507-
});
508-
509-
expect(keyHandler).toHaveBeenCalledWith(
510-
expect.objectContaining({
511-
name: 'backspace',
512-
ctrl: false,
513-
}),
514-
);
515-
});
516-
});
517-
518434
describe('paste mode', () => {
519435
it.each([
520436
{

packages/cli/src/ui/contexts/KeypressContext.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -651,20 +651,8 @@ function* emitKeys(
651651
// tab
652652
name = 'tab';
653653
alt = escaped;
654-
} else if (ch === '\b') {
655-
// ctrl+h / ctrl+backspace (windows terminals send \x08 for ctrl+backspace)
656-
name = 'backspace';
657-
// In Windows environments, \b is sent for Ctrl+Backspace (standard backspace is translated to \x7f).
658-
// We scope this to Windows/WT_SESSION to avoid breaking other unixes where \b is a plain backspace.
659-
if (
660-
typeof process !== 'undefined' &&
661-
(process.env?.['OS'] === 'Windows_NT' || !!process.env?.['WT_SESSION'])
662-
) {
663-
ctrl = true;
664-
}
665-
alt = escaped;
666-
} else if (ch === '\x7f') {
667-
// backspace
654+
} else if (ch === '\b' || ch === '\x7f') {
655+
// backspace or ctrl+h
668656
name = 'backspace';
669657
alt = escaped;
670658
} else if (ch === ESC) {

0 commit comments

Comments
 (0)