Support paste markers split across writes. (#11977)

This commit is contained in:
Tommaso Sciortino
2025-10-24 18:52:03 -07:00
committed by GitHub
parent 81006605c8
commit 145e099ca5
5 changed files with 281 additions and 68 deletions
@@ -46,7 +46,7 @@ class MockStdin extends EventEmitter {
pause = vi.fn();
write(text: string) {
this.emit('data', Buffer.from(text));
this.emit('data', text);
}
}
@@ -381,6 +381,61 @@ describe('KeypressContext - Kitty Protocol', () => {
}),
);
});
it('should paste start code split over multiple writes', async () => {
const keyHandler = vi.fn();
const pastedText = 'pasted content';
const { result } = renderHook(() => useKeypressContext(), { wrapper });
act(() => result.current.subscribe(keyHandler));
act(() => {
// Split PASTE_START into two parts
stdin.write(PASTE_START.slice(0, 3));
stdin.write(PASTE_START.slice(3));
stdin.write(pastedText);
stdin.write(PASTE_END);
});
await waitFor(() => {
expect(keyHandler).toHaveBeenCalledTimes(1);
});
expect(keyHandler).toHaveBeenCalledWith(
expect.objectContaining({
paste: true,
sequence: pastedText,
}),
);
});
it('should paste end code split over multiple writes', async () => {
const keyHandler = vi.fn();
const pastedText = 'pasted content';
const { result } = renderHook(() => useKeypressContext(), { wrapper });
act(() => result.current.subscribe(keyHandler));
act(() => {
stdin.write(PASTE_START);
stdin.write(pastedText);
// Split PASTE_END into two parts
stdin.write(PASTE_END.slice(0, 3));
stdin.write(PASTE_END.slice(3));
});
await waitFor(() => {
expect(keyHandler).toHaveBeenCalledTimes(1);
});
expect(keyHandler).toHaveBeenCalledWith(
expect.objectContaining({
paste: true,
sequence: pastedText,
}),
);
});
});
describe('debug keystroke logging', () => {