From 8d01db6d53e4f71c9f87da30e391a9b6f2b33ca3 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Fri, 31 Mar 2017 11:08:46 +0200 Subject: [PATCH] :bug: split git open file/changes into two sets of commands fixes #23729 --- extensions/git/package.json | 32 +++++++++++++++++++++++++++++--- extensions/git/src/commands.ts | 32 +++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/extensions/git/package.json b/extensions/git/package.json index ff9689c9739..a1748f0d2f6 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -63,6 +63,24 @@ "dark": "resources/icons/dark/open-file.svg" } }, + { + "command": "git.openChangeFromUri", + "title": "%command.openChange%", + "category": "Git", + "icon": { + "light": "resources/icons/light/open-change.svg", + "dark": "resources/icons/dark/open-change.svg" + } + }, + { + "command": "git.openFileFromUri", + "title": "%command.openFile%", + "category": "Git", + "icon": { + "light": "resources/icons/light/open-file.svg", + "dark": "resources/icons/dark/open-file.svg" + } + }, { "command": "git.stage", "title": "%command.stage%", @@ -228,10 +246,18 @@ }, { "command": "git.openChange", - "when": "config.git.enabled && scmProvider == git && gitState == idle" + "when": "false" }, { "command": "git.openFile", + "when": "false" + }, + { + "command": "git.openChangeFromUri", + "when": "config.git.enabled && scmProvider == git && gitState == idle" + }, + { + "command": "git.openFileFromUri", "when": "config.git.enabled && scmProvider == git && gitState == idle" }, { @@ -524,12 +550,12 @@ ], "editor/title": [ { - "command": "git.openFile", + "command": "git.openFileFromUri", "group": "navigation", "when": "config.git.enabled && scmProvider == git && isInDiffEditor && resourceScheme != extension" }, { - "command": "git.openChange", + "command": "git.openChangeFromUri", "group": "navigation", "when": "config.git.enabled && scmProvider == git && !isInDiffEditor && resourceScheme != extension" } diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 80047705480..851fb50fb17 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -261,10 +261,32 @@ export class CommandCenter { return await this._openResource(resource); } + @command('git.openFileFromUri') + async openFileFromUri(uri?: Uri): Promise { + const resource = this.getSCMResource(uri); + + if (!resource) { + return; + } + + return await commands.executeCommand('vscode.open', resource.resourceUri); + } + + @command('git.openChangeFromUri') + async openChangeFromUri(uri?: Uri): Promise { + const resource = this.getSCMResource(uri); + + if (!resource) { + return; + } + + return await this._openResource(resource); + } + @command('git.stage') async stage(...resourceStates: SourceControlResourceState[]): Promise { if (resourceStates.length === 0) { - const resource = this.getActiveEditorSCMResource(); + const resource = this.getSCMResource(); if (!resource) { return; @@ -370,7 +392,7 @@ export class CommandCenter { @command('git.unstage') async unstage(...resourceStates: SourceControlResourceState[]): Promise { if (resourceStates.length === 0) { - const resource = this.getActiveEditorSCMResource(); + const resource = this.getSCMResource(); if (!resource) { return; @@ -438,7 +460,7 @@ export class CommandCenter { @command('git.clean') async clean(...resourceStates: SourceControlResourceState[]): Promise { if (resourceStates.length === 0) { - const resource = this.getActiveEditorSCMResource(); + const resource = this.getSCMResource(); if (!resource) { return; @@ -791,8 +813,8 @@ export class CommandCenter { return result; } - private getActiveEditorSCMResource(): Resource | undefined { - let uri = window.activeTextEditor && window.activeTextEditor.document.uri; + private getSCMResource(uri?: Uri): Resource | undefined { + uri = uri ? uri : window.activeTextEditor && window.activeTextEditor.document.uri; if (!uri) { return undefined; -- GitLab