mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-04 02:11:11 -07:00
fix(ui): Clear input prompt on Escape key press (#13335)
This commit is contained in:
@@ -648,15 +648,17 @@ Logging in with Google... Please restart Gemini CLI to continue.
|
||||
}
|
||||
}, [config, historyManager]);
|
||||
|
||||
const cancelHandlerRef = useRef<() => void>(() => {});
|
||||
const cancelHandlerRef = useRef<(shouldRestorePrompt?: boolean) => void>(
|
||||
() => {},
|
||||
);
|
||||
|
||||
const getPreferredEditor = useCallback(
|
||||
() => settings.merged.general?.preferredEditor as EditorType,
|
||||
[settings.merged.general?.preferredEditor],
|
||||
);
|
||||
|
||||
const onCancelSubmit = useCallback(() => {
|
||||
cancelHandlerRef.current();
|
||||
const onCancelSubmit = useCallback((shouldRestorePrompt?: boolean) => {
|
||||
cancelHandlerRef.current(shouldRestorePrompt);
|
||||
}, []);
|
||||
|
||||
const {
|
||||
@@ -710,36 +712,39 @@ Logging in with Google... Please restart Gemini CLI to continue.
|
||||
submitQuery,
|
||||
});
|
||||
|
||||
cancelHandlerRef.current = useCallback(() => {
|
||||
const pendingHistoryItems = [
|
||||
...pendingSlashCommandHistoryItems,
|
||||
...pendingGeminiHistoryItems,
|
||||
];
|
||||
if (isToolExecuting(pendingHistoryItems)) {
|
||||
buffer.setText(''); // Just clear the prompt
|
||||
return;
|
||||
}
|
||||
cancelHandlerRef.current = useCallback(
|
||||
(shouldRestorePrompt: boolean = true) => {
|
||||
const pendingHistoryItems = [
|
||||
...pendingSlashCommandHistoryItems,
|
||||
...pendingGeminiHistoryItems,
|
||||
];
|
||||
if (isToolExecuting(pendingHistoryItems)) {
|
||||
buffer.setText(''); // Just clear the prompt
|
||||
return;
|
||||
}
|
||||
|
||||
const lastUserMessage = userMessages.at(-1);
|
||||
let textToSet = lastUserMessage || '';
|
||||
const lastUserMessage = userMessages.at(-1);
|
||||
let textToSet = shouldRestorePrompt ? lastUserMessage || '' : '';
|
||||
|
||||
const queuedText = getQueuedMessagesText();
|
||||
if (queuedText) {
|
||||
textToSet = textToSet ? `${textToSet}\n\n${queuedText}` : queuedText;
|
||||
clearQueue();
|
||||
}
|
||||
const queuedText = getQueuedMessagesText();
|
||||
if (queuedText) {
|
||||
textToSet = textToSet ? `${textToSet}\n\n${queuedText}` : queuedText;
|
||||
clearQueue();
|
||||
}
|
||||
|
||||
if (textToSet) {
|
||||
buffer.setText(textToSet);
|
||||
}
|
||||
}, [
|
||||
buffer,
|
||||
userMessages,
|
||||
getQueuedMessagesText,
|
||||
clearQueue,
|
||||
pendingSlashCommandHistoryItems,
|
||||
pendingGeminiHistoryItems,
|
||||
]);
|
||||
if (textToSet || !shouldRestorePrompt) {
|
||||
buffer.setText(textToSet);
|
||||
}
|
||||
},
|
||||
[
|
||||
buffer,
|
||||
userMessages,
|
||||
getQueuedMessagesText,
|
||||
clearQueue,
|
||||
pendingSlashCommandHistoryItems,
|
||||
pendingGeminiHistoryItems,
|
||||
],
|
||||
);
|
||||
|
||||
const handleFinalSubmit = useCallback(
|
||||
(submittedValue: string) => {
|
||||
|
||||
Reference in New Issue
Block a user