Revamp KeypressContext (#12746)

This commit is contained in:
Tommaso Sciortino
2025-11-09 08:45:04 -08:00
committed by GitHub
parent b9ca374e84
commit 4774384583
16 changed files with 891 additions and 1660 deletions
+12 -19
View File
@@ -38,7 +38,7 @@ class MockStdin extends EventEmitter {
}
}
describe.each([true, false])(`useKeypress with useKitty=%s`, (useKitty) => {
describe(`useKeypress with useKitty=%s`, () => {
let stdin: MockStdin;
const mockSetRawMode = vi.fn();
const onKeypress = vi.fn();
@@ -50,7 +50,7 @@ describe.each([true, false])(`useKeypress with useKitty=%s`, (useKitty) => {
return null;
}
return render(
<KeypressProvider kittyProtocolEnabled={useKitty}>
<KeypressProvider>
<TestComponent />
</KeypressProvider>,
);
@@ -196,20 +196,13 @@ describe.each([true, false])(`useKeypress with useKitty=%s`, (useKitty) => {
stdin.write('do');
});
if (useKitty) {
vi.advanceTimersByTime(60); // wait for kitty timeout
expect(onKeypress).toHaveBeenCalledExactlyOnceWith(
expect.objectContaining({ sequence: '\x1B[200do' }),
);
} else {
expect(onKeypress).toHaveBeenCalledWith(
expect.objectContaining({ sequence: '\x1B[200d' }),
);
expect(onKeypress).toHaveBeenCalledWith(
expect.objectContaining({ sequence: 'o' }),
);
expect(onKeypress).toHaveBeenCalledTimes(2);
}
expect(onKeypress).toHaveBeenCalledWith(
expect.objectContaining({ sequence: '\x1B[200d' }),
);
expect(onKeypress).toHaveBeenCalledWith(
expect.objectContaining({ sequence: 'o' }),
);
expect(onKeypress).toHaveBeenCalledTimes(2);
});
it('should handle back to back pastes', () => {
@@ -249,11 +242,11 @@ describe.each([true, false])(`useKeypress with useKitty=%s`, (useKitty) => {
const pasteText = 'pasted';
await act(async () => {
stdin.write(PASTE_START.slice(0, 3));
vi.advanceTimersByTime(50);
vi.advanceTimersByTime(40);
stdin.write(PASTE_START.slice(3) + pasteText.slice(0, 3));
vi.advanceTimersByTime(50);
vi.advanceTimersByTime(40);
stdin.write(pasteText.slice(3) + PASTE_END.slice(0, 3));
vi.advanceTimersByTime(50);
vi.advanceTimersByTime(40);
stdin.write(PASTE_END.slice(3));
});
expect(onKeypress).toHaveBeenCalledWith(