mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-15 17:02:50 +00:00
fix ctrl c conflict behavior
This commit is contained in:
@@ -2127,6 +2127,23 @@ describe('AppContainer State Management', () => {
|
||||
});
|
||||
|
||||
describe('CTRL+C', () => {
|
||||
it('should not trigger quit flow when input buffer has text', async () => {
|
||||
mockedUseTextBuffer.mockReturnValue({
|
||||
text: 'hello world',
|
||||
setText: vi.fn(),
|
||||
lines: ['hello world'],
|
||||
cursor: [0, 11],
|
||||
handleInput: vi.fn().mockReturnValue(false),
|
||||
});
|
||||
await setupKeypressTest();
|
||||
|
||||
pressKey('\x03'); // Ctrl+C
|
||||
|
||||
expect(mockCancelOngoingRequest).not.toHaveBeenCalled();
|
||||
expect(mockHandleSlashCommand).not.toHaveBeenCalled();
|
||||
unmount();
|
||||
});
|
||||
|
||||
it('should cancel ongoing request on first press', async () => {
|
||||
mockedUseGeminiStream.mockReturnValue({
|
||||
...DEFAULT_GEMINI_STREAM_MOCK,
|
||||
|
||||
@@ -1649,11 +1649,14 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
||||
[config, handleSlashCommand],
|
||||
);
|
||||
|
||||
const { pressCount: ctrlCPressCount, handlePress: handleCtrlCPress } =
|
||||
useRepeatedKeyPress({
|
||||
windowMs: WARNING_PROMPT_DURATION_MS,
|
||||
onRepeat: handleExitRepeat,
|
||||
});
|
||||
const {
|
||||
pressCount: ctrlCPressCount,
|
||||
handlePress: handleCtrlCPress,
|
||||
resetCount: resetCtrlCPress,
|
||||
} = useRepeatedKeyPress({
|
||||
windowMs: WARNING_PROMPT_DURATION_MS,
|
||||
onRepeat: handleExitRepeat,
|
||||
});
|
||||
|
||||
const { pressCount: ctrlDPressCount, handlePress: handleCtrlDPress } =
|
||||
useRepeatedKeyPress({
|
||||
@@ -1830,6 +1833,20 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
keyMatchers[Command.QUIT](key) &&
|
||||
keyMatchers[Command.CLEAR_INPUT](key) &&
|
||||
isInputActive &&
|
||||
streamingState === StreamingState.Idle &&
|
||||
buffer.text.length > 0
|
||||
) {
|
||||
// Let InputPrompt handle Ctrl+C as edit.clear when there is text.
|
||||
// This preserves documented behavior and allows prompt-level state
|
||||
// (completions/history) to reset correctly.
|
||||
resetCtrlCPress();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keyMatchers[Command.QUIT](key)) {
|
||||
// If the user presses Ctrl+C, we want to cancel any ongoing requests.
|
||||
// This should happen regardless of the count.
|
||||
@@ -2062,6 +2079,10 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
||||
startRecording,
|
||||
stopRecording,
|
||||
mouseMode,
|
||||
isInputActive,
|
||||
streamingState,
|
||||
buffer,
|
||||
resetCtrlCPress,
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user