fix ctrl c conflict behavior

This commit is contained in:
cynthialong0-0
2026-05-13 16:46:27 +00:00
parent 8cda688fe2
commit 83f46557c0
2 changed files with 43 additions and 5 deletions

View File

@@ -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,

View File

@@ -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,
],
);