Skip to content

Commit

Permalink
search: make sure to override previous results on completion
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi committed Dec 19, 2024
1 parent 0d152b7 commit 1ffc258
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## [Smoother search and bug fixes] - 2024-12-14
## [Search bug fix] - 2024-12-19

- **search**: Fix some issues where results do not reset when a search returns no results or fails.

## [Smoother search and bug fixes](https://github.com/raycast/extensions/pull/15862) - 2024-12-14

- **search**: Opening a query in browser now correctly preserves the selected pattern type from the pattern type selector.
- **search**: Typing during ongoing searches should feel less jittery, as the suggestion view is now less likely to show up randomly.
Expand Down
10 changes: 10 additions & 0 deletions src/hooks/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,19 @@ export function useSearch(src: Sourcegraph, maxResults: number) {
};
});
},
onDone: () => {
setState((oldState) => {
if (oldState.isPreviousResults) {
return { ...oldState, results: [], isPreviousResults: false };
}
return oldState;
});
},
});
} catch (error) {
ExpandableToast(push, "Unexpected error", "Search failed", String(error)).show();
// Reset the search state
setState((oldState) => ({ ...oldState, loading: false, results: [], isPreviousResults: false }));
} finally {
setState((oldState) => ({
...oldState,
Expand Down
6 changes: 5 additions & 1 deletion src/sourcegraph/stream-search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface SearchHandlers {
onSuggestions: (suggestions: Suggestion[], top: boolean) => void;
onAlert: (alert: Alert) => void;
onProgress: (progress: Progress) => void;
onDone: () => void;
}

// 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
Expand Down Expand Up @@ -232,6 +233,9 @@ export async function performSearch(
});

// done indicator
stream.addEventListener("done", resolveStream);
stream.addEventListener("done", () => {
handlers.onDone();
resolveStream();
});
});
}

0 comments on commit 1ffc258

Please sign in to comment.