fix(cli): prevent Escape from clearing input buffer (#17083) (#26339)

This commit is contained in:
Coco Sheng
2026-05-01 14:58:55 -04:00
committed by GitHub
parent b14a29efa2
commit 997f461cad
5 changed files with 172 additions and 115 deletions
+22 -19
View File
@@ -1127,18 +1127,21 @@ Logging in with Google... Restarting Gemini CLI to continue.
}
}, [config, historyManager]);
const cancelHandlerRef = useRef<(shouldRestorePrompt?: boolean) => void>(
() => {},
);
const cancelHandlerRef = useRef<
(shouldRestorePrompt?: boolean, clearBuffer?: boolean) => void
>(() => {});
const onCancelSubmit = useCallback((shouldRestorePrompt?: boolean) => {
if (shouldRestorePrompt) {
setPendingRestorePrompt(true);
} else {
setPendingRestorePrompt(false);
cancelHandlerRef.current(false);
}
}, []);
const onCancelSubmit = useCallback(
(shouldRestorePrompt?: boolean, clearBuffer: boolean = false) => {
if (shouldRestorePrompt) {
setPendingRestorePrompt(true);
} else {
setPendingRestorePrompt(false);
cancelHandlerRef.current(false, clearBuffer);
}
},
[],
);
useEffect(() => {
if (pendingRestorePrompt) {
@@ -1321,18 +1324,18 @@ Logging in with Google... Restarting Gemini CLI to continue.
});
cancelHandlerRef.current = useCallback(
(shouldRestorePrompt: boolean = true) => {
if (isToolAwaitingConfirmation(pendingHistoryItems)) {
(shouldRestorePrompt: boolean = true, clearBuffer: boolean = false) => {
if (!clearBuffer && isToolAwaitingConfirmation(pendingHistoryItems)) {
return; // Don't clear - user may be composing a follow-up message
}
if (isToolExecuting(pendingHistoryItems)) {
buffer.setText(''); // Clear for Ctrl+C cancellation
return;
}
// If cancelling (shouldRestorePrompt=false), never modify the buffer
// User is in control - preserve whatever text they typed, pasted, or restored
// If cancelling (shouldRestorePrompt=false):
if (!shouldRestorePrompt) {
// Clear the buffer if explicitly requested (e.g., Ctrl+C)
if (clearBuffer) {
buffer.setText('');
}
// Otherwise (e.g., Escape), user is in control - preserve whatever text they typed
return;
}