mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
fix(cli): fix history navigation regression after prompt autocomplete (#18752)
This commit is contained in:
@@ -281,7 +281,10 @@ describe('InputPrompt', () => {
|
||||
navigateDown: vi.fn(),
|
||||
handleSubmit: vi.fn(),
|
||||
};
|
||||
mockedUseInputHistory.mockReturnValue(mockInputHistory);
|
||||
mockedUseInputHistory.mockImplementation(({ onSubmit }) => {
|
||||
mockInputHistory.handleSubmit = vi.fn((val) => onSubmit(val));
|
||||
return mockInputHistory;
|
||||
});
|
||||
|
||||
mockReverseSearchCompletion = {
|
||||
suggestions: [],
|
||||
@@ -4093,7 +4096,7 @@ describe('InputPrompt', () => {
|
||||
beforeEach(() => {
|
||||
props.userMessages = ['first message', 'second message'];
|
||||
// Mock useInputHistory to actually call onChange
|
||||
mockedUseInputHistory.mockImplementation(({ onChange }) => ({
|
||||
mockedUseInputHistory.mockImplementation(({ onChange, onSubmit }) => ({
|
||||
navigateUp: () => {
|
||||
onChange('second message', 'start');
|
||||
return true;
|
||||
@@ -4102,7 +4105,7 @@ describe('InputPrompt', () => {
|
||||
onChange('first message', 'end');
|
||||
return true;
|
||||
},
|
||||
handleSubmit: vi.fn(),
|
||||
handleSubmit: vi.fn((val) => onSubmit(val)),
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
@@ -337,31 +337,6 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
],
|
||||
);
|
||||
|
||||
const handleSubmit = useCallback(
|
||||
(submittedValue: string) => {
|
||||
const trimmedMessage = submittedValue.trim();
|
||||
const isSlash = isSlashCommand(trimmedMessage);
|
||||
|
||||
const isShell = shellModeActive;
|
||||
if (
|
||||
(isSlash || isShell) &&
|
||||
streamingState === StreamingState.Responding
|
||||
) {
|
||||
setQueueErrorMessage(
|
||||
`${isShell ? 'Shell' : 'Slash'} commands cannot be queued`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
handleSubmitAndClear(trimmedMessage);
|
||||
},
|
||||
[
|
||||
handleSubmitAndClear,
|
||||
shellModeActive,
|
||||
streamingState,
|
||||
setQueueErrorMessage,
|
||||
],
|
||||
);
|
||||
|
||||
const customSetTextAndResetCompletionSignal = useCallback(
|
||||
(newText: string, cursorPosition?: 'start' | 'end' | number) => {
|
||||
buffer.setText(newText, cursorPosition);
|
||||
@@ -381,6 +356,26 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
onChange: customSetTextAndResetCompletionSignal,
|
||||
});
|
||||
|
||||
const handleSubmit = useCallback(
|
||||
(submittedValue: string) => {
|
||||
const trimmedMessage = submittedValue.trim();
|
||||
const isSlash = isSlashCommand(trimmedMessage);
|
||||
|
||||
const isShell = shellModeActive;
|
||||
if (
|
||||
(isSlash || isShell) &&
|
||||
streamingState === StreamingState.Responding
|
||||
) {
|
||||
setQueueErrorMessage(
|
||||
`${isShell ? 'Shell' : 'Slash'} commands cannot be queued`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
inputHistory.handleSubmit(trimmedMessage);
|
||||
},
|
||||
[inputHistory, shellModeActive, streamingState, setQueueErrorMessage],
|
||||
);
|
||||
|
||||
// Effect to reset completion if history navigation just occurred and set the text
|
||||
useEffect(() => {
|
||||
if (suppressCompletion) {
|
||||
@@ -858,7 +853,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
showSuggestions && activeSuggestionIndex > -1
|
||||
? suggestions[activeSuggestionIndex].value
|
||||
: buffer.text;
|
||||
handleSubmitAndClear(textToSubmit);
|
||||
handleSubmit(textToSubmit);
|
||||
resetState();
|
||||
setActive(false);
|
||||
return true;
|
||||
@@ -1155,7 +1150,6 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||
setShellModeActive,
|
||||
onClearScreen,
|
||||
inputHistory,
|
||||
handleSubmitAndClear,
|
||||
handleSubmit,
|
||||
shellHistory,
|
||||
reverseSearchCompletion,
|
||||
|
||||
Reference in New Issue
Block a user