Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions packages/cli/src/ui/AppContainer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2245,12 +2245,39 @@ describe('AppContainer State Management', () => {
await setupKeypressTest();

pressKey('\x04'); // Ctrl+D
expect(mockHandleSlashCommand).not.toHaveBeenCalled();

// Should only be called once, so count is 1, not quitting yet.
pressKey('\x04'); // Ctrl+D again
// Should still not quit because buffer is non-empty
expect(mockHandleSlashCommand).not.toHaveBeenCalled();
unmount();
});

pressKey('\x04'); // Ctrl+D
// Now count is 2, it should quit.
it('should quit on second press after buffer becomes empty', async () => {
// Start with non-empty buffer
const mockReturn = {
text: 'some text',
setText: vi.fn(),
lines: ['some text'],
cursor: [0, 9],
handleInput: vi.fn().mockReturnValue(false),
};
mockedUseTextBuffer.mockReturnValue(mockReturn);
await setupKeypressTest();

pressKey('\x04'); // Ctrl+D - ignored (buffer non-empty)
expect(mockHandleSlashCommand).not.toHaveBeenCalled();

// Buffer becomes empty (user deleted all text)
mockedUseTextBuffer.mockReturnValue({
...mockReturn,
text: '',
lines: [''],
cursor: [0, 0],
});
rerender();

pressKey('\x04', 2); // Ctrl+D twice with empty buffer
expect(mockHandleSlashCommand).toHaveBeenCalledWith(
'/quit',
undefined,
Expand Down
9 changes: 7 additions & 2 deletions packages/cli/src/ui/AppContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1702,8 +1702,13 @@ Logging in with Google... Restarting Gemini CLI to continue.
handleCtrlCPress();
return true;
} else if (keyMatchers[Command.EXIT](key)) {
handleCtrlDPress();
return true;
// Only treat Ctrl+D as exit when input is empty (standard shell behavior).
// When there is input text, let it fall through to DELETE_CHAR_RIGHT.
if (bufferRef.current.text === '') {
handleCtrlDPress();
return true;
}
return false;
} else if (keyMatchers[Command.SUSPEND_APP](key)) {
handleSuspend();
} else if (
Expand Down
Loading