Skip to content

Commit ce4cd83

Browse files
authored
if no selection, link to full file (#74)
If there is no selection (line and column of start and end are the same), link to the whole file (no `#L1` suffix).
1 parent 2ddde38 commit ce4cd83

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Changed
1313

1414
- Extension now calls `git` instead of manually reading `.git/` files. (#75)
15+
- When there is no selection, link to the whole file on GitHub (#74)
1516

1617
## 3.4.0 - 2026-03-07
1718

src/providers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ export class Github extends BaseProvider {
113113
PROVIDER_NAME = "github"
114114

115115
buildLines({ start, end }: ISelection): string {
116+
if (start.line === end.line && start.character === end.character) {
117+
return ""
118+
}
119+
116120
let line = `L${start.line + 1}`
117121
if (start.character !== 0) {
118122
line += `C${start.character + 1}`

src/test/suite/providers.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,28 @@ suite("Github", async () => {
150150
assert.deepEqual(result, expected)
151151
}
152152
})
153+
test("if we have no selection on the first line, don't select anything", async () => {
154+
const gh = new Github(
155+
{
156+
github: { hostnames: ["github.mycompany.com"] },
157+
},
158+
"origin",
159+
async () => "git@github.mycompany.com:recipeyak/recipeyak.git",
160+
)
161+
const result = await gh.getUrls({
162+
selection: {
163+
start: { line: 0, character: 0 },
164+
end: { line: 0, character: 0 },
165+
},
166+
head: createBranch("master"),
167+
relativeFilePath: "frontend/src/components/App.tsx",
168+
})
169+
170+
assert.deepEqual(
171+
result?.blobUrl,
172+
"https://github.mycompany.com/recipeyak/recipeyak/blob/master/frontend/src/components/App.tsx",
173+
)
174+
})
153175
})
154176

155177
suite("Gitlab", async () => {

0 commit comments

Comments
 (0)