Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cardinal/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,13 @@ function App() {
if (activeTab !== 'files') {
return;
}
if (event.key === 'Enter') {
queueSearch(event.currentTarget.value, {
immediate: true,
onSearchCommitted: updateHistoryFromInput,
});
return;
}
if (event.key !== 'ArrowUp' && event.key !== 'ArrowDown') {
return;
}
Expand All @@ -508,7 +515,7 @@ function App() {
event.preventDefault();
handleHistoryNavigation(event.key === 'ArrowUp' ? 'older' : 'newer');
},
[activeTab, handleHistoryNavigation],
[activeTab, handleHistoryNavigation, queueSearch, updateHistoryFromInput],
);

const handleHorizontalSync = useCallback((scrollLeft: number) => {
Expand Down Expand Up @@ -600,7 +607,6 @@ function App() {
// Switch to files: sync with reducer-managed search state and cancel pending timers
ensureHistoryBuffer('');
resetSearchQuery();
cancelPendingSearches();
}
},
[
Expand Down
11 changes: 9 additions & 2 deletions cardinal/src/hooks/useFileSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type SearchParams = {
};

type QueueSearchOptions = {
immediate?: boolean;
onSearchCommitted?: (query: string) => void;
};

Expand Down Expand Up @@ -285,13 +286,19 @@ export function useFileSearch(): UseFileSearchResult {
const queueSearch = useCallback(
(query: string, options?: QueueSearchOptions) => {
updateSearchParams({ query });
cancelTimer(debounceTimerRef);
cancelPendingSearches();
if (options?.immediate) {
options.onSearchCommitted?.(query);
void handleSearch({ query });
return;
}

debounceTimerRef.current = setTimeout(() => {
options?.onSearchCommitted?.(query);
handleSearch({ query });
}, SEARCH_DEBOUNCE_MS);
},
[handleSearch, updateSearchParams],
[cancelPendingSearches, handleSearch, updateSearchParams],
);

const resetSearchQuery = useCallback(() => {
Expand Down