summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/useReverseSearchCompletion.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/cli/src/ui/hooks/useReverseSearchCompletion.tsx')
-rw-r--r--packages/cli/src/ui/hooks/useReverseSearchCompletion.tsx9
1 files changed, 7 insertions, 2 deletions
diff --git a/packages/cli/src/ui/hooks/useReverseSearchCompletion.tsx b/packages/cli/src/ui/hooks/useReverseSearchCompletion.tsx
index 1cc7e602..3fb9217e 100644
--- a/packages/cli/src/ui/hooks/useReverseSearchCompletion.tsx
+++ b/packages/cli/src/ui/hooks/useReverseSearchCompletion.tsx
@@ -41,12 +41,17 @@ export function useReverseSearchCompletion(
navigateDown,
} = useCompletion();
- // whenever reverseSearchActive is on, filter history
useEffect(() => {
if (!reverseSearchActive) {
resetCompletionState();
+ }
+ }, [reverseSearchActive, resetCompletionState]);
+
+ useEffect(() => {
+ if (!reverseSearchActive) {
return;
}
+
const q = buffer.text.toLowerCase();
const matches = shellHistory.reduce<Suggestion[]>((acc, cmd) => {
const idx = cmd.toLowerCase().indexOf(q);
@@ -55,6 +60,7 @@ export function useReverseSearchCompletion(
}
return acc;
}, []);
+
setSuggestions(matches);
setShowSuggestions(matches.length > 0);
setActiveSuggestionIndex(matches.length > 0 ? 0 : -1);
@@ -62,7 +68,6 @@ export function useReverseSearchCompletion(
buffer.text,
shellHistory,
reverseSearchActive,
- resetCompletionState,
setActiveSuggestionIndex,
setShowSuggestions,
setSuggestions,