Skip to content

Commit 2f31f12

Browse files
committed
search: fix off-by-one links
1 parent bdc3837 commit 2f31f12

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- **search**: Fix off-by-one issue when opening to `content` match results.
56
- **search**: Migrate away from the [deprecated `/search/stream` endpoint](https://about.sourcegraph.com/blog/release/3.36/) in favour of `/.api/search/stream`.
67

78
## [Jan 22nd, 2022](https://github.com/raycast/extensions/pull/729)

‎src/sourcegraph/stream-search/index.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,18 @@ export async function performSearch(
8383
handlers.onResults(
8484
event.data.map((match): SearchResult => {
8585
const url = `${src.instance}${getMatchUrl(match)}`;
86-
if (match.type === "commit") {
87-
// Commit stuff comes already markdown-formatted?? so strip formatting
88-
match.label = stripMarkdown.processSync(match.label)?.value.toString().split(`› `).pop() || "";
89-
match.detail = stripMarkdown.processSync(match.detail)?.value.toString();
86+
switch (match.type) {
87+
case "commit":
88+
// Commit stuff comes already markdown-formatted?? so strip formatting
89+
match.label = stripMarkdown.processSync(match.label)?.value.toString().split(`› `).pop() || "";
90+
match.detail = stripMarkdown.processSync(match.detail)?.value.toString();
91+
break;
92+
case "content":
93+
// Line number appears 0-indexed, for ease of use increment it so links
94+
// aren't off by 1.
95+
match.lineMatches.forEach((l) => {
96+
l.lineNumber += 1;
97+
});
9098
}
9199
return { url, match };
92100
})

0 commit comments

Comments
 (0)