Skip to content

Commit

Permalink
Fixes #1458 - restores range copying
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Apr 14, 2021
1 parent 7a4b551 commit f67a582
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 16 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

- Adds an alternate _Copy Remote File Url_ command (`gitlens.copyRemoteFileUrlWithoutRange`) to copy the remote url of the file without including any line range

### Fixed

- Fixes [#1458](https://github.com/eamodio/vscode-gitlens/issues/1458) - "Copy Remote File Url" not showing line ranges

## [11.4.0] - 2021-04-08

### Added
Expand Down
34 changes: 24 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"onCommand:gitlens.openFileFromRemote",
"onCommand:gitlens.openFileOnRemote",
"onCommand:gitlens.copyRemoteFileUrlToClipboard",
"onCommand:gitlens.copyRemoteFileUrlWithoutRange",
"onCommand:gitlens.openFileOnRemoteFrom",
"onCommand:gitlens.copyRemoteFileUrlFrom",
"onCommand:gitlens.openBlamePriorToChange",
Expand Down Expand Up @@ -3726,6 +3727,15 @@
"light": "images/light/icon-copy-link.svg"
}
},
{
"command": "gitlens.copyRemoteFileUrlWithoutRange",
"title": "Copy Remote File Url",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-copy-link.svg",
"light": "images/light/icon-copy-link.svg"
}
},
{
"command": "gitlens.openFileOnRemoteFrom",
"title": "Open File on Remote From...",
Expand Down Expand Up @@ -5614,6 +5624,10 @@
"command": "gitlens.copyRemoteFileUrlToClipboard",
"when": "gitlens:activeFileStatus =~ /tracked/ && gitlens:activeFileStatus =~ /remotes/"
},
{
"command": "gitlens.copyRemoteFileUrlWithoutRange",
"when": "false"
},
{
"command": "gitlens.openFileOnRemoteFrom",
"when": "gitlens:activeFileStatus =~ /tracked/ && gitlens:activeFileStatus =~ /remotes/"
Expand Down Expand Up @@ -6748,7 +6762,7 @@
],
"editor/title/context": [
{
"command": "gitlens.copyRemoteFileUrlToClipboard",
"command": "gitlens.copyRemoteFileUrlWithoutRange",
"when": "gitlens:enabled && gitlens:hasRemotes && config.gitlens.menus.editorTab.clipboard",
"group": "1_cutcopypaste@100"
},
Expand All @@ -6766,7 +6780,7 @@
"command": "gitlens.openFileOnRemote",
"when": "gitlens:enabled && gitlens:hasRemotes && config.gitlens.menus.editorTab.remote",
"group": "2_gitlens@2",
"alt": "gitlens.copyRemoteFileUrlToClipboard"
"alt": "gitlens.copyRemoteFileUrlWithoutRange"
},
{
"command": "gitlens.openFileOnRemoteFrom",
Expand Down Expand Up @@ -6795,7 +6809,7 @@
"command": "gitlens.openFileOnRemote",
"when": "!explorerResourceIsRoot && !explorerResourceIsFolder && gitlens:enabled && gitlens:hasRemotes && config.gitlens.menus.explorer.remote",
"group": "4_gitlens@1",
"alt": "gitlens.copyRemoteFileUrlToClipboard"
"alt": "gitlens.copyRemoteFileUrlWithoutRange"
},
{
"command": "gitlens.openFileOnRemoteFrom",
Expand All @@ -6819,7 +6833,7 @@
"group": "4_timeline@3"
},
{
"command": "gitlens.copyRemoteFileUrlToClipboard",
"command": "gitlens.copyRemoteFileUrlWithoutRange",
"when": "!explorerResourceIsRoot && !explorerResourceIsFolder && gitlens:enabled && gitlens:hasRemotes && config.gitlens.menus.explorer.clipboard",
"group": "6_copypath@100"
}
Expand Down Expand Up @@ -6892,7 +6906,7 @@
"command": "gitlens.openFileOnRemote",
"when": "gitlens:enabled && gitlens:hasRemotes && scmProvider == git && scmResourceGroup =~ /^(workingTree|index|merge)$/ && config.gitlens.menus.scmItem.remote",
"group": "navigation@96",
"alt": "gitlens.copyRemoteFileUrlToClipboard"
"alt": "gitlens.copyRemoteFileUrlWithoutRange"
},
{
"command": "gitlens.openFileOnRemoteFrom",
Expand All @@ -6906,7 +6920,7 @@
"group": "1_modification@2"
},
{
"command": "gitlens.copyRemoteFileUrlToClipboard",
"command": "gitlens.copyRemoteFileUrlWithoutRange",
"when": "gitlens:enabled && gitlens:hasRemotes && scmProvider == git && scmResourceGroup =~ /^(workingTree|index|merge)$/ && config.gitlens.menus.scmItem.clipboard",
"group": "2_gitlens@1"
},
Expand Down Expand Up @@ -7982,7 +7996,7 @@
"command": "gitlens.openFileOnRemote",
"when": "viewItem =~ /gitlens:file\\b((?=.*?\\b\\+committed\\b)|:results)/ && gitlens:hasRemotes",
"group": "inline@99",
"alt": "gitlens.copyRemoteFileUrlToClipboard"
"alt": "gitlens.copyRemoteFileUrlWithoutRange"
},
{
"submenu": "gitlens/commit/file/commit",
Expand Down Expand Up @@ -8028,7 +8042,7 @@
"command": "gitlens.openFileOnRemote",
"when": "viewItem =~ /gitlens:file\\b((?=.*?\\b\\+committed\\b)|:results)/ && gitlens:hasRemotes",
"group": "2_gitlens_quickopen@5",
"alt": "gitlens.copyRemoteFileUrlToClipboard"
"alt": "gitlens.copyRemoteFileUrlWithoutRange"
},
{
"command": "gitlens.openFileHistory",
Expand Down Expand Up @@ -8075,7 +8089,7 @@
"command": "gitlens.openFileOnRemote",
"when": "viewItem =~ /gitlens:(history:(file|line)|status:file)\\b/ && gitlens:hasRemotes",
"group": "5_gitlens_open@2",
"alt": "gitlens.copyRemoteFileUrlToClipboard"
"alt": "gitlens.copyRemoteFileUrlWithoutRange"
},
{
"command": "gitlens.views.openPullRequest",
Expand Down Expand Up @@ -8719,7 +8733,7 @@
"group": "2_gitlens@1"
},
{
"command": "gitlens.copyRemoteFileUrlToClipboard",
"command": "gitlens.copyRemoteFileUrlWithoutRange",
"when": "viewItem =~ /gitlens:(file\\b(?=.*?\\b\\+committed\\b)|history:(file|line)|status:file)\\b/ && gitlens:hasRemotes",
"group": "2_gitlens@2"
}
Expand Down
1 change: 1 addition & 0 deletions src/commands/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export enum Commands {
CopyRemoteCommitUrl = 'gitlens.copyRemoteCommitUrl',
CopyRemoteComparisonUrl = 'gitlens.copyRemoteComparisonUrl',
CopyRemoteFileUrl = 'gitlens.copyRemoteFileUrlToClipboard',
CopyRemoteFileUrlWithoutRange = 'gitlens.copyRemoteFileUrlWithoutRange',
CopyRemoteFileUrlFrom = 'gitlens.copyRemoteFileUrlFrom',
CopyRemotePullRequestUrl = 'gitlens.copyRemotePullRequestUrl',
CopyRemoteRepositoryUrl = 'gitlens.copyRemoteRepositoryUrl',
Expand Down
21 changes: 15 additions & 6 deletions src/commands/openFileOnRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
Commands.OpenFileOnRemote,
Commands.Deprecated_OpenFileInRemote,
Commands.CopyRemoteFileUrl,
Commands.CopyRemoteFileUrlWithoutRange,
Commands.OpenFileOnRemoteFrom,
Commands.CopyRemoteFileUrlFrom,
]);
Expand All @@ -45,12 +46,18 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
protected async preExecute(context: CommandContext, args?: OpenFileOnRemoteCommandArgs) {
let uri = context.uri;

if (context.type === 'uris' || context.type === 'scm-states') {
if (context.command === Commands.CopyRemoteFileUrlWithoutRange) {
args = { ...args, range: false };
} else if (isCommandContextViewNodeHasCommit(context)) {
}

if (isCommandContextViewNodeHasCommit(context)) {
args = { ...args, range: false };

if (context.command === Commands.CopyRemoteFileUrl || context.command === Commands.CopyRemoteFileUrlFrom) {
if (
context.command === Commands.CopyRemoteFileUrl ||
context.command === Commands.CopyRemoteFileUrlWithoutRange ||
context.command === Commands.CopyRemoteFileUrlFrom
) {
// If it is a StatusFileNode then don't include the sha, since it hasn't been pushed yet
args.sha = context.node instanceof StatusFileNode ? undefined : context.node.commit.sha;
} else if (isCommandContextViewNodeHasBranch(context)) {
Expand All @@ -64,7 +71,11 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
uri = context.node.uri ?? context.uri;
}

if (context.command === Commands.CopyRemoteFileUrl || context.command === Commands.CopyRemoteFileUrlFrom) {
if (
context.command === Commands.CopyRemoteFileUrl ||
context.command === Commands.CopyRemoteFileUrlWithoutRange ||
context.command === Commands.CopyRemoteFileUrlFrom
) {
args = { ...args, clipboard: true };
if (args.sha == null) {
const uri = getCommandUri(context.uri, context.editor);
Expand All @@ -89,8 +100,6 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {

if (context.command === Commands.OpenFileOnRemoteFrom || context.command === Commands.CopyRemoteFileUrlFrom) {
args = { ...args, pickBranchOrTag: true, range: false };
} else if (context.command === Commands.CopyRemoteFileUrl && context.type === 'unknown') {
args = { ...args, range: false };
}

return this.execute(context.editor, uri, args);
Expand Down

0 comments on commit f67a582

Please sign in to comment.