From 828cf0917c21c77aeb9721c9e516f98766dc1eb4 Mon Sep 17 00:00:00 2001 From: Charles Packer Date: Tue, 20 Jan 2026 20:09:51 -0800 Subject: [PATCH] fix: place cursor at end when navigating command history (#611) Co-authored-by: Letta --- src/cli/components/InputRich.tsx | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/cli/components/InputRich.tsx b/src/cli/components/InputRich.tsx index 1ed790b..ee22881 100644 --- a/src/cli/components/InputRich.tsx +++ b/src/cli/components/InputRich.tsx @@ -407,7 +407,12 @@ export function Input({ // On first wrapped line // First press: move to start, second press: queue edit or history - if (currentCursorPosition > 0 && !atStartBoundary) { + // Skip the two-step behavior if already browsing history - go straight to navigation + if ( + currentCursorPosition > 0 && + !atStartBoundary && + historyIndex === -1 + ) { // First press - move cursor to start setCursorPos(0); setAtStartBoundary(true); @@ -442,13 +447,15 @@ export function Input({ setTemporaryInput(value); // Go to most recent command setHistoryIndex(history.length - 1); - setValue(history[history.length - 1] ?? ""); - setCursorPos(0); // Ensure cursor at start for consistent navigation + const historyEntry = history[history.length - 1] ?? ""; + setValue(historyEntry); + setCursorPos(historyEntry.length); // Cursor at end (traditional terminal behavior) } else if (historyIndex > 0) { // Go to older command setHistoryIndex(historyIndex - 1); - setValue(history[historyIndex - 1] ?? ""); - setCursorPos(0); // Ensure cursor at start for consistent navigation + const olderEntry = history[historyIndex - 1] ?? ""; + setValue(olderEntry); + setCursorPos(olderEntry.length); // Cursor at end (traditional terminal behavior) } } else if (key.downArrow) { if (currentWrappedLine < totalWrappedLines - 1) { @@ -472,7 +479,12 @@ export function Input({ // On last wrapped line // First press: move to end, second press: navigate history - if (currentCursorPosition < value.length && !atEndBoundary) { + // Skip the two-step behavior if already browsing history - go straight to navigation + if ( + currentCursorPosition < value.length && + !atEndBoundary && + historyIndex === -1 + ) { // First press - move cursor to end setCursorPos(value.length); setAtEndBoundary(true); @@ -487,8 +499,9 @@ export function Input({ if (historyIndex < history.length - 1) { // Go to newer command setHistoryIndex(historyIndex + 1); - setValue(history[historyIndex + 1] ?? ""); - setCursorPos(0); // Ensure cursor at start for consistent navigation + const newerEntry = history[historyIndex + 1] ?? ""; + setValue(newerEntry); + setCursorPos(newerEntry.length); // Cursor at end (traditional terminal behavior) } else { // At the end of history - restore temporary input setHistoryIndex(-1);