Add Esc-Esc to clear prompt when it's not empty (#17131)

This commit is contained in:
Adib234
2026-01-20 19:32:26 -05:00
committed by GitHub
parent 3b626e7c61
commit e1fd5be429
7 changed files with 82 additions and 12 deletions

View File

@@ -1893,10 +1893,35 @@ describe('InputPrompt', () => {
unmount();
});
it('should submit /rewind on double ESC', async () => {
it('should submit /rewind on double ESC when buffer is empty', async () => {
const onEscapePromptChange = vi.fn();
props.onEscapePromptChange = onEscapePromptChange;
props.buffer.setText('');
vi.mocked(props.buffer.setText).mockClear();
const { stdin, unmount } = renderWithProviders(
<InputPrompt {...props} />,
{
uiState: {
history: [{ id: 1, type: 'user', text: 'test' }],
},
},
);
await act(async () => {
stdin.write('\x1B\x1B');
vi.advanceTimersByTime(100);
expect(props.onSubmit).toHaveBeenCalledWith('/rewind');
});
unmount();
});
it('should clear the buffer on esc esc if it has text', async () => {
const onEscapePromptChange = vi.fn();
props.onEscapePromptChange = onEscapePromptChange;
props.buffer.setText('some text');
vi.mocked(props.buffer.setText).mockClear();
const { stdin, unmount } = renderWithProviders(
<InputPrompt {...props} />,
@@ -1906,7 +1931,8 @@ describe('InputPrompt', () => {
stdin.write('\x1B\x1B');
vi.advanceTimersByTime(100);
expect(props.onSubmit).toHaveBeenCalledWith('/rewind');
expect(props.buffer.setText).toHaveBeenCalledWith('');
expect(props.onSubmit).not.toHaveBeenCalledWith('/rewind');
});
unmount();
});