mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-11 05:41:08 -07:00
fix(ui): prevent escape key from cancelling requests in shell mode (#21245)
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
useKeypressContext,
|
||||
ESC_TIMEOUT,
|
||||
FAST_RETURN_TIMEOUT,
|
||||
KeypressPriority,
|
||||
type Key,
|
||||
} from './KeypressContext.js';
|
||||
import { terminalCapabilityManager } from '../utils/terminalCapabilityManager.js';
|
||||
@@ -259,6 +260,48 @@ describe('KeypressContext', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should stop propagation when a higher priority handler returns true', async () => {
|
||||
const higherPriorityHandler = vi.fn(() => true);
|
||||
const lowerPriorityHandler = vi.fn();
|
||||
const { result } = await renderHookWithProviders(() =>
|
||||
useKeypressContext(),
|
||||
);
|
||||
|
||||
act(() => {
|
||||
result.current.subscribe(higherPriorityHandler, KeypressPriority.High);
|
||||
result.current.subscribe(lowerPriorityHandler, KeypressPriority.Normal);
|
||||
});
|
||||
|
||||
act(() => stdin.write('\x1b[27u'));
|
||||
|
||||
expect(higherPriorityHandler).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ name: 'escape' }),
|
||||
);
|
||||
expect(lowerPriorityHandler).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should continue propagation when a higher priority handler does not consume the event', async () => {
|
||||
const higherPriorityHandler = vi.fn(() => false);
|
||||
const lowerPriorityHandler = vi.fn();
|
||||
const { result } = await renderHookWithProviders(() =>
|
||||
useKeypressContext(),
|
||||
);
|
||||
|
||||
act(() => {
|
||||
result.current.subscribe(higherPriorityHandler, KeypressPriority.High);
|
||||
result.current.subscribe(lowerPriorityHandler, KeypressPriority.Normal);
|
||||
});
|
||||
|
||||
act(() => stdin.write('\x1b[27u'));
|
||||
|
||||
expect(higherPriorityHandler).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ name: 'escape' }),
|
||||
);
|
||||
expect(lowerPriorityHandler).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ name: 'escape' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle double Escape', async () => {
|
||||
const keyHandler = vi.fn();
|
||||
const { result } = await renderHookWithProviders(() =>
|
||||
|
||||
Reference in New Issue
Block a user