Support ctrl-C and Ctrl-D correctly Refactor so InputPrompt has priority over AppContainer for input handling. (#17993)

This commit is contained in:
Jacob Richman
2026-01-30 16:11:14 -08:00
committed by GitHub
parent 0fe8492569
commit 00fdb30211
6 changed files with 193 additions and 62 deletions
@@ -45,6 +45,8 @@ import { StreamingState } from '../types.js';
import { terminalCapabilityManager } from '../utils/terminalCapabilityManager.js';
import type { UIState } from '../contexts/UIStateContext.js';
import { isLowColorDepth } from '../utils/terminalUtils.js';
import { keyMatchers, Command } from '../keyMatchers.js';
import type { Key } from '../hooks/useKeypress.js';
vi.mock('../hooks/useShellHistory.js');
vi.mock('../hooks/useCommandCompletion.js');
@@ -169,7 +171,16 @@ describe('InputPrompt', () => {
allVisualLines: [''],
visualCursor: [0, 0],
visualScrollRow: 0,
handleInput: vi.fn(),
handleInput: vi.fn((key: Key) => {
if (keyMatchers[Command.CLEAR_INPUT](key)) {
if (mockBuffer.text.length > 0) {
mockBuffer.setText('');
return true;
}
return false;
}
return false;
}),
move: vi.fn(),
moveToOffset: vi.fn((offset: number) => {
mockBuffer.cursor = [0, offset];
@@ -499,6 +510,23 @@ describe('InputPrompt', () => {
unmount();
});
it('should clear the buffer and reset completion on Ctrl+C', async () => {
mockBuffer.text = 'some text';
const { stdin, unmount } = renderWithProviders(<InputPrompt {...props} />, {
uiActions,
});
await act(async () => {
stdin.write('\u0003'); // Ctrl+C
});
await waitFor(() => {
expect(mockBuffer.setText).toHaveBeenCalledWith('');
expect(mockCommandCompletion.resetCompletionState).toHaveBeenCalled();
});
unmount();
});
describe('clipboard image paste', () => {
beforeEach(() => {
vi.mocked(clipboardUtils.clipboardHasImage).mockResolvedValue(false);