diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d5600a..f1eaa39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Extension now calls `git` instead of manually reading `.git/` files. (#75) +- When there is no selection, link to the whole file on GitHub (#74) ## 3.4.0 - 2026-03-07 diff --git a/src/providers.ts b/src/providers.ts index 8321b21..4bfeaa5 100644 --- a/src/providers.ts +++ b/src/providers.ts @@ -113,6 +113,10 @@ export class Github extends BaseProvider { PROVIDER_NAME = "github" buildLines({ start, end }: ISelection): string { + if (start.line === end.line && start.character === end.character) { + return "" + } + let line = `L${start.line + 1}` if (start.character !== 0) { line += `C${start.character + 1}` diff --git a/src/test/suite/providers.test.ts b/src/test/suite/providers.test.ts index 998904b..17cd952 100644 --- a/src/test/suite/providers.test.ts +++ b/src/test/suite/providers.test.ts @@ -150,6 +150,28 @@ suite("Github", async () => { assert.deepEqual(result, expected) } }) + test("if we have no selection on the first line, don't select anything", async () => { + const gh = new Github( + { + github: { hostnames: ["github.mycompany.com"] }, + }, + "origin", + async () => "git@github.mycompany.com:recipeyak/recipeyak.git", + ) + const result = await gh.getUrls({ + selection: { + start: { line: 0, character: 0 }, + end: { line: 0, character: 0 }, + }, + head: createBranch("master"), + relativeFilePath: "frontend/src/components/App.tsx", + }) + + assert.deepEqual( + result?.blobUrl, + "https://github.mycompany.com/recipeyak/recipeyak/blob/master/frontend/src/components/App.tsx", + ) + }) }) suite("Gitlab", async () => {