summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/useInputHistory.ts
diff options
context:
space:
mode:
authorJacob Richman <[email protected]>2025-05-23 09:40:01 -0700
committerGitHub <[email protected]>2025-05-23 09:40:01 -0700
commita96ff934eacdedfea16ae91a0e63858b15c4b593 (patch)
tree6b3e38e56514e393b623182108d36b53605dbaa9 /packages/cli/src/ui/hooks/useInputHistory.ts
parenta008d8178015a182656ea8f5a39b9dde554da5ae (diff)
Fix bug updating the cursor after navigating history. (#507)
Diffstat (limited to 'packages/cli/src/ui/hooks/useInputHistory.ts')
-rw-r--r--packages/cli/src/ui/hooks/useInputHistory.ts14
1 files changed, 7 insertions, 7 deletions
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<number>(-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,
]);