From a96ff934eacdedfea16ae91a0e63858b15c4b593 Mon Sep 17 00:00:00 2001 From: Jacob Richman Date: Fri, 23 May 2025 09:40:01 -0700 Subject: Fix bug updating the cursor after navigating history. (#507) --- packages/cli/src/ui/hooks/useInputHistory.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'packages/cli/src/ui/hooks/useInputHistory.ts') diff --git a/packages/cli/src/ui/hooks/useInputHistory.ts b/packages/cli/src/ui/hooks/useInputHistory.ts index 90947662..8225d4fc 100644 --- a/packages/cli/src/ui/hooks/useInputHistory.ts +++ b/packages/cli/src/ui/hooks/useInputHistory.ts @@ -11,7 +11,7 @@ interface UseInputHistoryProps { onSubmit: (value: string) => void; isActive: boolean; currentQuery: string; // Renamed from query to avoid confusion - onChangeAndMoveCursor: (value: string) => void; + onChange: (value: string) => void; } interface UseInputHistoryReturn { @@ -25,7 +25,7 @@ export function useInputHistory({ onSubmit, isActive, currentQuery, - onChangeAndMoveCursor: setQueryAndMoveCursor, + onChange, }: UseInputHistoryProps): UseInputHistoryReturn { const [historyIndex, setHistoryIndex] = useState(-1); const [originalQueryBeforeNav, setOriginalQueryBeforeNav] = @@ -65,14 +65,14 @@ export function useInputHistory({ if (nextIndex !== historyIndex) { setHistoryIndex(nextIndex); const newValue = userMessages[userMessages.length - 1 - nextIndex]; - setQueryAndMoveCursor(newValue); // Call the prop passed from parent + onChange(newValue); return true; } return false; }, [ historyIndex, setHistoryIndex, - setQueryAndMoveCursor, + onChange, userMessages, isActive, currentQuery, // Use currentQuery from props @@ -88,17 +88,17 @@ export function useInputHistory({ if (nextIndex === -1) { // Reached the end of history navigation, restore original query - setQueryAndMoveCursor(originalQueryBeforeNav); + onChange(originalQueryBeforeNav); } else { const newValue = userMessages[userMessages.length - 1 - nextIndex]; - setQueryAndMoveCursor(newValue); + onChange(newValue); } return true; }, [ historyIndex, setHistoryIndex, originalQueryBeforeNav, - setQueryAndMoveCursor, + onChange, userMessages, isActive, ]); -- cgit v1.2.3