summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/components/InputPrompt.tsx
diff options
context:
space:
mode:
authorgoldyonatan <[email protected]>2025-07-18 01:30:39 +0300
committerGitHub <[email protected]>2025-07-17 22:30:39 +0000
commit6aac93ee075757fcb0b840012ff0abf0b17feea1 (patch)
treee37a3560d5de004aa50e64a1b1e8fc97669925b7 /packages/cli/src/ui/components/InputPrompt.tsx
parent761ffc63388201373e5d16f36c2af09be71b5933 (diff)
Fix #4220: allow up/down arrow to toggle history when only one sugges… (#4377)
Diffstat (limited to 'packages/cli/src/ui/components/InputPrompt.tsx')
-rw-r--r--packages/cli/src/ui/components/InputPrompt.tsx120
1 files changed, 62 insertions, 58 deletions
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<InputPromptProps> = ({
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<InputPromptProps> = ({
}
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<InputPromptProps> = ({
}
return;
}
+ }
+
+ 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 {
- 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;
- }
+ // 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 (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;
}
+ return;
}
// Newline insertion