diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f298a0..c4b0317 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## 3.3.0 - 2025-11-05 + +### Changed + +- Only add column offsets when they are non-zero for GitHub. (#68) + ## 3.2.2 - 2025-07-02 ### Fixed diff --git a/package.json b/package.json index 7783d95..350d4a1 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "githubinator", "displayName": "Githubinator", "description": "Quickly open files on Github and other providers. View blame information, copy permalinks and more. See the \"commands\" section of the README for more details.", - "version": "3.2.2", + "version": "3.3.0", "publisher": "chdsbd", "license": "SEE LICENSE IN LICENSE", "icon": "images/logo256.png", diff --git a/src/providers.ts b/src/providers.ts index 16f84fe..7db2c18 100644 --- a/src/providers.ts +++ b/src/providers.ts @@ -111,6 +111,18 @@ export function pathJoin(...args: string[]): string { export class Github extends BaseProvider { DEFAULT_HOSTNAMES = ["github.com"] PROVIDER_NAME = "github" + + buildLines({ start, end }: ISelection): string { + let line = `L${start.line + 1}` + if (start.character !== 0) { + line += `C${start.character + 1}` + } + line += `-L${end.line + 1}` + if (end.character !== 0) { + line += `C${end.character + 1}` + } + return line + } async getUrls({ selection, head, @@ -121,11 +133,7 @@ export class Github extends BaseProvider { return null } const rootUrl = `https://${repoInfo.hostname}/` - const { start, end } = selection - // Github uses 1-based indexing - const lines = `L${start.line + 1}C${start.character + 1}-L${ - end.line + 1 - }C${end.character + 1}` + const lines = this.buildLines(selection) const repoUrl = new url.URL( path.join(repoInfo.org, repoInfo.repo), rootUrl, diff --git a/src/test/suite/providers.test.ts b/src/test/suite/providers.test.ts index b06dcce..d3e390a 100644 --- a/src/test/suite/providers.test.ts +++ b/src/test/suite/providers.test.ts @@ -54,9 +54,9 @@ suite("Github", async () => { }) const expected = { blobUrl: - "https://github.com/recipeyak/recipeyak/blob/db99a912f5c4bffe11d91e163cd78ed96589611b/frontend/src/components/App.tsx#L18C1-L25C1", + "https://github.com/recipeyak/recipeyak/blob/db99a912f5c4bffe11d91e163cd78ed96589611b/frontend/src/components/App.tsx#L18-L25", blameUrl: - "https://github.com/recipeyak/recipeyak/blame/db99a912f5c4bffe11d91e163cd78ed96589611b/frontend/src/components/App.tsx#L18C1-L25C1", + "https://github.com/recipeyak/recipeyak/blame/db99a912f5c4bffe11d91e163cd78ed96589611b/frontend/src/components/App.tsx#L18-L25", compareUrl: "https://github.com/recipeyak/recipeyak/compare/db99a912f5c4bffe11d91e163cd78ed96589611b", historyUrl: @@ -87,17 +87,17 @@ suite("Github", async () => { ) const result = await gh.getUrls({ selection: { - start: { line: 17, character: 0 }, - end: { line: 24, character: 0 }, + start: { line: 17, character: 4 }, + end: { line: 24, character: 5 }, }, head: createBranch("master"), relativeFilePath: "frontend/src/components/App.tsx", }) const expected = { blobUrl: - "https://github.mycompany.com/recipeyak/recipeyak/blob/master/frontend/src/components/App.tsx#L18C1-L25C1", + "https://github.mycompany.com/recipeyak/recipeyak/blob/master/frontend/src/components/App.tsx#L18C5-L25C6", blameUrl: - "https://github.mycompany.com/recipeyak/recipeyak/blame/master/frontend/src/components/App.tsx#L18C1-L25C1", + "https://github.mycompany.com/recipeyak/recipeyak/blame/master/frontend/src/components/App.tsx#L18C5-L25C6", compareUrl: "https://github.mycompany.com/recipeyak/recipeyak/compare/master", historyUrl: