mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-12 07:01:09 -07:00
fix: preserve prompt text when cancelling streaming (#21103)
Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
@@ -3145,7 +3145,7 @@ describe('AppContainer State Management', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('clears the prompt when onCancelSubmit is called with shouldRestorePrompt=false', async () => {
|
||||
it('preserves buffer when cancelling, even if empty (user is in control)', async () => {
|
||||
let unmount: () => void;
|
||||
await act(async () => {
|
||||
const result = renderAppContainer();
|
||||
@@ -3161,7 +3161,45 @@ describe('AppContainer State Management', () => {
|
||||
onCancelSubmit(false);
|
||||
});
|
||||
|
||||
expect(mockSetText).toHaveBeenCalledWith('');
|
||||
// Should NOT modify buffer when cancelling - user is in control
|
||||
expect(mockSetText).not.toHaveBeenCalled();
|
||||
|
||||
unmount!();
|
||||
});
|
||||
|
||||
it('preserves prompt text when cancelling streaming, even if same as last message (regression test for issue #13387)', async () => {
|
||||
// Mock buffer with text that user typed while streaming (same as last message)
|
||||
const promptText = 'What is Python?';
|
||||
mockedUseTextBuffer.mockReturnValue({
|
||||
text: promptText,
|
||||
setText: mockSetText,
|
||||
});
|
||||
|
||||
// Mock input history with same message
|
||||
mockedUseInputHistoryStore.mockReturnValue({
|
||||
inputHistory: [promptText],
|
||||
addInput: vi.fn(),
|
||||
initializeFromLogger: vi.fn(),
|
||||
});
|
||||
|
||||
let unmount: () => void;
|
||||
await act(async () => {
|
||||
const result = renderAppContainer();
|
||||
unmount = result.unmount;
|
||||
});
|
||||
await waitFor(() => expect(capturedUIState).toBeTruthy());
|
||||
|
||||
const { onCancelSubmit } = extractUseGeminiStreamArgs(
|
||||
mockedUseGeminiStream.mock.lastCall!,
|
||||
);
|
||||
|
||||
act(() => {
|
||||
// Simulate Escape key cancelling streaming (shouldRestorePrompt=false)
|
||||
onCancelSubmit(false);
|
||||
});
|
||||
|
||||
// Should NOT call setText - prompt should be preserved regardless of content
|
||||
expect(mockSetText).not.toHaveBeenCalled();
|
||||
|
||||
unmount!();
|
||||
});
|
||||
|
||||
@@ -1220,8 +1220,15 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
||||
return;
|
||||
}
|
||||
|
||||
// If cancelling (shouldRestorePrompt=false), never modify the buffer
|
||||
// User is in control - preserve whatever text they typed, pasted, or restored
|
||||
if (!shouldRestorePrompt) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Restore the last message when shouldRestorePrompt=true
|
||||
const lastUserMessage = inputHistory.at(-1);
|
||||
let textToSet = shouldRestorePrompt ? lastUserMessage || '' : '';
|
||||
let textToSet = lastUserMessage || '';
|
||||
|
||||
const queuedText = getQueuedMessagesText();
|
||||
if (queuedText) {
|
||||
@@ -1229,7 +1236,7 @@ Logging in with Google... Restarting Gemini CLI to continue.
|
||||
clearQueue();
|
||||
}
|
||||
|
||||
if (textToSet || !shouldRestorePrompt) {
|
||||
if (textToSet) {
|
||||
buffer.setText(textToSet);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user