Skip to content

Commit 12cdc4a

Browse files
suanbugthesystem
authored andcommitted
Add option to not include line numbers except when there's a selection (#57)
* Add requireSelectionForLines functionality * Mention in README that line range will be included if there's a selection * Mention requireSelectionForLines in README * annotate markdown block as JS, so that we can place useful comments
1 parent 9214e62 commit 12cdc4a

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Press <kbd>F1</kbd> and type `Copy GitHub link to clipboard`.
4747

4848
![copy](screenshots/copy.png?raw=true "Copy function")
4949

50+
(The URL for Github will also include line ranges if there are lines selected in the editor)
51+
5052
Press <kbd>F1</kbd> and type `Open Pull Request`.
5153

5254
![copy](screenshots/pull-req-cmd.png?raw=true "Copy function")
@@ -66,9 +68,10 @@ Right click on explorer item and choose `Open in GitHub` or `Copy GitHub link to
6668

6769
Add following line into workspace settings;
6870

69-
```json
71+
```js
7072
{
71-
"openInGitHub.gitHubDomain":"your custom github domain here"
73+
"openInGitHub.gitHubDomain":"your custom github domain here",
74+
"openInGitHub.requireSelectionForLines":false // If enabled, the copied or opened URL won't include line number(s) unless there's an active selection
7275
}
7376
```
7477

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
],
5656
"default": "github.com",
5757
"description": "Configure a custom Github domain. Useful for Github entreprise"
58+
},
59+
"openInGitHub.requireSelectionForLines": {
60+
"type": "boolean",
61+
"default": false,
62+
"description": "If enabled, the copied or opened URL won't include line number(s) unless there's an active selection"
5863
}
5964
}
6065
},

src/extension.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var gitRev = require('git-rev-2');
1616
var findParentDir = require('find-parent-dir');
1717

1818
const gitProvider = require('./gitProvider');
19+
const requireSelectionForLines = workspace.getConfiguration('openInGitHub').get('requireSelectionForLines');
1920

2021
function getGitProviderLink(cb, fileFsPath, lines, pr) {
2122
var cwd = workspace.rootPath;
@@ -48,14 +49,18 @@ function getGitProviderLink(cb, fileFsPath, lines, pr) {
4849
cb(provider.prUrl(branch));
4950
}
5051
else {
51-
if (lines[0] == lines[1]) {
52-
cb(provider.webUrl(branch, subdir, lines[0]));
52+
if (lines) {
53+
if (lines[0] == lines[1]) {
54+
cb(provider.webUrl(branch, subdir, lines[0]));
55+
}
56+
else {
57+
cb(provider.webUrl(branch, subdir, lines[0], lines[1]));
58+
}
5359
}
5460
else {
55-
cb(provider.webUrl(branch, subdir, lines[0], lines[1]));
61+
cb(provider.webUrl(branch, subdir));
5662
}
5763
}
58-
5964
});
6065
});
6166
}
@@ -70,10 +75,20 @@ function getGitProviderLinkForCurrentEditorLines(cb) {
7075
var editor = Window.activeTextEditor;
7176
if (editor) {
7277
var fileFsPath = editor.document.uri.fsPath;
73-
getGitProviderLink(cb, fileFsPath, getSelectedLines(editor));
78+
79+
if (includeLines(editor)) {
80+
getGitProviderLink(cb, fileFsPath, getSelectedLines(editor));
81+
}
82+
else {
83+
getGitProviderLinkForFile(fileFsPath, cb);
84+
}
7485
}
7586
}
7687

88+
function includeLines(editor) {
89+
return !requireSelectionForLines || !editor.selection.isEmpty;
90+
}
91+
7792
function getSelectedLines(editor) {
7893
var anchorLineIndex = editor.selection.anchor.line + 1;
7994
var activeLineIndex = editor.selection.active.line + 1;

0 commit comments

Comments
 (0)