Skip to content

Commit

Permalink
search: preserve pattern type
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi committed Dec 6, 2024
1 parent ae599ab commit 6b2fe8c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- **search**: Opening a query in browser now correctly preserves the selected pattern type from the pattern type selector.

## [Search improvements, pattern selector, and proxy support](https://github.com/raycast/extensions/pull/15625) - 2024-11-30

- **search**: The search pattern selector is now enabled by default, allowing you to easily toggle between standard, literal, regexp, and other search patterns. This can be disabled in the extension preferences if you find the dropdown takes up too much space in the search bar.
Expand Down
15 changes: 11 additions & 4 deletions src/components/SearchCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default function SearchCommand({ src, props }: { src: Sourcegraph; props?
icon={{ source: Icon.Window }}
actions={
<ActionPanel>
<Action.OpenInBrowser url={getQueryURL(src, searchText)} />
<Action.OpenInBrowser url={getQueryURL(src, searchText, patternType)} />
</ActionPanel>
}
/>
Expand Down Expand Up @@ -144,6 +144,7 @@ export default function SearchCommand({ src, props }: { src: Sourcegraph; props?
key={`result-item-${i}`}
searchResult={searchResult}
searchText={searchText}
patternType={patternType}
src={src}
setSearchText={setSearchText}
/>
Expand Down Expand Up @@ -226,8 +227,12 @@ function resultActions(url: string, customActions?: CustomResultActions) {
);
}

function getQueryURL(src: Sourcegraph, query: string) {
return link.new(src, "/search", new URLSearchParams({ q: query }));
function getQueryURL(src: Sourcegraph, query: string, pattern: PatternType | undefined) {
const params: Record<string, string> = { q: query };
if (pattern) {
params.patternType = pattern;
}
return link.new(src, "/search", new URLSearchParams(params));
}

// https://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
Expand Down Expand Up @@ -297,15 +302,17 @@ function makeFileActions(src: Sourcegraph, opts: { path: string; repository: str
function SearchResultItem({
searchResult,
searchText,
patternType,
src,
setSearchText,
}: {
searchResult: SearchResult;
searchText: string;
patternType: PatternType | undefined;
src: Sourcegraph;
setSearchText: (text: string) => void;
}) {
const queryURL = getQueryURL(src, searchText);
const queryURL = getQueryURL(src, searchText, patternType);
const { match } = searchResult;

// Branches is a common property for setting a revision
Expand Down

0 comments on commit 6b2fe8c

Please sign in to comment.