diff --git a/packages/cli/src/ui/components/InputPrompt.tsx b/packages/cli/src/ui/components/InputPrompt.tsx index 41c88d6c..7cefdc08 100644 --- a/packages/cli/src/ui/components/InputPrompt.tsx +++ b/packages/cli/src/ui/components/InputPrompt.tsx @@ -95,7 +95,9 @@ export const InputPrompt: React.FC = ({ const inputHistory = useInputHistory({ userMessages, onSubmit: handleSubmitAndClear, - isActive: !completion.showSuggestions && !shellModeActive, + isActive: + (!completion.showSuggestions || completion.suggestions.length === 1) && + !shellModeActive, currentQuery: buffer.text, onChange: customSetTextAndResetCompletionSignal, }); @@ -265,13 +267,15 @@ export const InputPrompt: React.FC = ({ } if (completion.showSuggestions) { - if (key.name === 'up') { - completion.navigateUp(); - return; - } - if (key.name === 'down') { - completion.navigateDown(); - return; + if (completion.suggestions.length > 1) { + if (key.name === 'up') { + completion.navigateUp(); + return; + } + if (key.name === 'down') { + completion.navigateDown(); + return; + } } if (key.name === 'tab' || (key.name === 'return' && !key.ctrl)) { @@ -286,61 +290,61 @@ export const InputPrompt: React.FC = ({ } return; } - } else { - if (!shellModeActive) { - if (key.ctrl && key.name === 'p') { - inputHistory.navigateUp(); - return; - } - if (key.ctrl && key.name === 'n') { - inputHistory.navigateDown(); - return; - } - // Handle arrow-up/down for history on single-line or at edges - if ( - key.name === 'up' && - (buffer.allVisualLines.length === 1 || - (buffer.visualCursor[0] === 0 && buffer.visualScrollRow === 0)) - ) { - inputHistory.navigateUp(); - return; - } - if ( - key.name === 'down' && - (buffer.allVisualLines.length === 1 || - buffer.visualCursor[0] === buffer.allVisualLines.length - 1) - ) { - inputHistory.navigateDown(); - return; - } - } else { - // Shell History Navigation - if (key.name === 'up') { - const prevCommand = shellHistory.getPreviousCommand(); - if (prevCommand !== null) buffer.setText(prevCommand); - return; - } - if (key.name === 'down') { - const nextCommand = shellHistory.getNextCommand(); - if (nextCommand !== null) buffer.setText(nextCommand); - return; - } - } + } - if (key.name === 'return' && !key.ctrl && !key.meta && !key.paste) { - if (buffer.text.trim()) { - const [row, col] = buffer.cursor; - const line = buffer.lines[row]; - const charBefore = col > 0 ? cpSlice(line, col - 1, col) : ''; - if (charBefore === '\\') { - buffer.backspace(); - buffer.newline(); - } else { - handleSubmitAndClear(buffer.text); - } - } + if (!shellModeActive) { + if (key.ctrl && key.name === 'p') { + inputHistory.navigateUp(); return; } + if (key.ctrl && key.name === 'n') { + inputHistory.navigateDown(); + return; + } + // Handle arrow-up/down for history on single-line or at edges + if ( + key.name === 'up' && + (buffer.allVisualLines.length === 1 || + (buffer.visualCursor[0] === 0 && buffer.visualScrollRow === 0)) + ) { + inputHistory.navigateUp(); + return; + } + if ( + key.name === 'down' && + (buffer.allVisualLines.length === 1 || + buffer.visualCursor[0] === buffer.allVisualLines.length - 1) + ) { + inputHistory.navigateDown(); + return; + } + } else { + // Shell History Navigation + if (key.name === 'up') { + const prevCommand = shellHistory.getPreviousCommand(); + if (prevCommand !== null) buffer.setText(prevCommand); + return; + } + if (key.name === 'down') { + const nextCommand = shellHistory.getNextCommand(); + if (nextCommand !== null) buffer.setText(nextCommand); + return; + } + } + + if (key.name === 'return' && !key.ctrl && !key.meta && !key.paste) { + if (buffer.text.trim()) { + const [row, col] = buffer.cursor; + const line = buffer.lines[row]; + const charBefore = col > 0 ? cpSlice(line, col - 1, col) : ''; + if (charBefore === '\\') { + buffer.backspace(); + buffer.newline(); + } else { + handleSubmitAndClear(buffer.text); + } + } + return; } // Newline insertion