Skip to content

Commit 1ffc258

Browse files
committed
search: make sure to override previous results on completion
1 parent 0d152b7 commit 1ffc258

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

3-
## [Smoother search and bug fixes] - 2024-12-14
3+
## [Search bug fix] - 2024-12-19
4+
5+
- **search**: Fix some issues where results do not reset when a search returns no results or fails.
6+
7+
## [Smoother search and bug fixes](https://github.com/raycast/extensions/pull/15862) - 2024-12-14
48

59
- **search**: Opening a query in browser now correctly preserves the selected pattern type from the pattern type selector.
610
- **search**: Typing during ongoing searches should feel less jittery, as the suggestion view is now less likely to show up randomly.

src/hooks/search.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,19 @@ export function useSearch(src: Sourcegraph, maxResults: number) {
164164
};
165165
});
166166
},
167+
onDone: () => {
168+
setState((oldState) => {
169+
if (oldState.isPreviousResults) {
170+
return { ...oldState, results: [], isPreviousResults: false };
171+
}
172+
return oldState;
173+
});
174+
},
167175
});
168176
} catch (error) {
169177
ExpandableToast(push, "Unexpected error", "Search failed", String(error)).show();
178+
// Reset the search state
179+
setState((oldState) => ({ ...oldState, loading: false, results: [], isPreviousResults: false }));
170180
} finally {
171181
setState((oldState) => ({
172182
...oldState,

src/sourcegraph/stream-search/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface SearchHandlers {
3737
onSuggestions: (suggestions: Suggestion[], top: boolean) => void;
3838
onAlert: (alert: Alert) => void;
3939
onProgress: (progress: Progress) => void;
40+
onDone: () => void;
4041
}
4142

4243
// Copied by hand from https://sourcegraph.sourcegraph.com/search?q=repo:%5Egithub%5C.com/sourcegraph/sourcegraph%24+f:graphql+%22enum+SearchPatternType+%7B%22&patternType=keyword&case=yes&sm=0
@@ -232,6 +233,9 @@ export async function performSearch(
232233
});
233234

234235
// done indicator
235-
stream.addEventListener("done", resolveStream);
236+
stream.addEventListener("done", () => {
237+
handlers.onDone();
238+
resolveStream();
239+
});
236240
});
237241
}

0 commit comments

Comments
 (0)