Fix: add back fastreturn support (#16440)

This commit is contained in:
Tommaso Sciortino
2026-01-12 13:31:33 -08:00
committed by GitHub
parent 8437ce940a
commit e049d5e4e8
4 changed files with 90 additions and 2 deletions

View File

@@ -16,7 +16,9 @@ import {
KeypressProvider,
useKeypressContext,
ESC_TIMEOUT,
FAST_RETURN_TIMEOUT,
} from './KeypressContext.js';
import { terminalCapabilityManager } from '../utils/terminalCapabilityManager.js';
import { useStdin } from 'ink';
import { EventEmitter } from 'node:events';
@@ -154,6 +156,53 @@ describe('KeypressContext', () => {
);
});
describe('Fast return buffering', () => {
let kittySpy: ReturnType<typeof vi.spyOn>;
beforeEach(() => {
kittySpy = vi
.spyOn(terminalCapabilityManager, 'isKittyProtocolEnabled')
.mockReturnValue(false);
});
afterEach(() => kittySpy.mockRestore());
it('should buffer return key pressed quickly after another key', async () => {
const { keyHandler } = setupKeypressTest();
act(() => stdin.write('a'));
expect(keyHandler).toHaveBeenLastCalledWith(
expect.objectContaining({ name: 'a' }),
);
act(() => stdin.write('\r'));
expect(keyHandler).toHaveBeenLastCalledWith(
expect.objectContaining({
name: '',
sequence: '\r',
insertable: true,
}),
);
});
it('should NOT buffer return key if delay is long enough', async () => {
const { keyHandler } = setupKeypressTest();
act(() => stdin.write('a'));
vi.advanceTimersByTime(FAST_RETURN_TIMEOUT + 1);
act(() => stdin.write('\r'));
expect(keyHandler).toHaveBeenLastCalledWith(
expect.objectContaining({
name: 'return',
}),
);
});
});
describe('Escape key handling', () => {
it('should recognize escape key (keycode 27) in kitty protocol', async () => {
const { keyHandler } = setupKeypressTest();