From a7bed2cc4cf5c9e727358ec5dec05dcc662f317b Mon Sep 17 00:00:00 2001 From: Wesley Tanaka <35872+wtanaka@users.noreply.github.com> Date: Mon, 23 Mar 2026 17:13:13 -0700 Subject: [PATCH] fix(cli): prevent Ctrl+D exit when input buffer is not empty (#23306) Co-authored-by: wtanaka.com --- packages/cli/src/ui/AppContainer.test.tsx | 9 ++------- packages/cli/src/ui/AppContainer.tsx | 4 ++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/cli/src/ui/AppContainer.test.tsx b/packages/cli/src/ui/AppContainer.test.tsx index 313573a573..9078366bf9 100644 --- a/packages/cli/src/ui/AppContainer.test.tsx +++ b/packages/cli/src/ui/AppContainer.test.tsx @@ -2157,13 +2157,8 @@ describe('AppContainer State Management', () => { expect(mockHandleSlashCommand).not.toHaveBeenCalled(); pressKey('\x04'); // Ctrl+D - // Now count is 2, it should quit. - expect(mockHandleSlashCommand).toHaveBeenCalledWith( - '/quit', - undefined, - undefined, - false, - ); + // It should still not quit because buffer is non-empty. + expect(mockHandleSlashCommand).not.toHaveBeenCalled(); unmount(); }); diff --git a/packages/cli/src/ui/AppContainer.tsx b/packages/cli/src/ui/AppContainer.tsx index 68b4f339e2..cf84746beb 100644 --- a/packages/cli/src/ui/AppContainer.tsx +++ b/packages/cli/src/ui/AppContainer.tsx @@ -1702,6 +1702,10 @@ Logging in with Google... Restarting Gemini CLI to continue. handleCtrlCPress(); return true; } else if (keyMatchers[Command.EXIT](key)) { + // If the input field is non-empty, do not exit. + if (bufferRef.current.text.length > 0) { + return false; + } handleCtrlDPress(); return true; } else if (keyMatchers[Command.SUSPEND_APP](key)) {