diff --git a/extensions/git/package.json b/extensions/git/package.json index 5564a3d409b..0301d7f471d 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -33,12 +33,20 @@ { "command": "git.openChange", "title": "%command.openChange%", - "category": "Git" + "category": "Git", + "icon": { + "light": "resources/icons/light/open-change.svg", + "dark": "resources/icons/dark/open-change.svg" + } }, { "command": "git.openFile", "title": "%command.openFile%", - "category": "Git" + "category": "Git", + "icon": { + "light": "resources/icons/light/open-file.svg", + "dark": "resources/icons/dark/open-file.svg" + } }, { "command": "git.stage", @@ -368,6 +376,18 @@ "when": "scmProvider == git && scmResourceGroup == workingTree", "group": "inline" } + ], + "editor/title": [ + { + "command": "git.openFile", + "group": "navigation", + "when": "isInDiffEditor" + }, + { + "command": "git.openChange", + "group": "navigation", + "when": "!isInDiffEditor" + } ] }, "configuration": { diff --git a/extensions/git/resources/icons/dark/open-change.svg b/extensions/git/resources/icons/dark/open-change.svg new file mode 100644 index 00000000000..c951728abac --- /dev/null +++ b/extensions/git/resources/icons/dark/open-change.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/extensions/git/resources/icons/dark/open-file.svg b/extensions/git/resources/icons/dark/open-file.svg new file mode 100644 index 00000000000..f6302185aa4 --- /dev/null +++ b/extensions/git/resources/icons/dark/open-file.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/extensions/git/resources/icons/light/open-change.svg b/extensions/git/resources/icons/light/open-change.svg new file mode 100644 index 00000000000..3a205509bca --- /dev/null +++ b/extensions/git/resources/icons/light/open-change.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/extensions/git/resources/icons/light/open-file.svg b/extensions/git/resources/icons/light/open-file.svg new file mode 100644 index 00000000000..85a001dccc2 --- /dev/null +++ b/extensions/git/resources/icons/light/open-file.svg @@ -0,0 +1,3 @@ + +]> \ No newline at end of file diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index ea4f80e423c..10af98114e3 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -108,17 +108,6 @@ export class CommandCenter { await this.model.status(); } - @command('git.openChange') - async openChange(uri: Uri): Promise { - const resource = resolveGitResource(uri); - - if (!resource) { - return; - } - - return this.open(resource); - } - async open(resource: Resource): Promise { const left = this.getLeftResource(resource); const right = this.getRightResource(resource); @@ -131,10 +120,10 @@ export class CommandCenter { return; } - return commands.executeCommand('vscode.open', right); + return await commands.executeCommand('vscode.open', right); } - return commands.executeCommand('vscode.diff', left, right, title); + return await commands.executeCommand('vscode.diff', left, right, title); } private getLeftResource(resource: Resource): Uri | undefined { @@ -192,13 +181,32 @@ export class CommandCenter { @command('git.openFile') async openFile(uri: Uri): Promise { - const resource = resolveGitResource(uri); + const scmResource = resolveGitResource(uri); - if (!resource) { - return; + if (scmResource) { + return await commands.executeCommand('vscode.open', scmResource.uri); } - return commands.executeCommand('vscode.open', resource.uri); + return await commands.executeCommand('vscode.open', uri.with({ scheme: 'file' })); + } + + @command('git.openChange') + async openChange(uri: Uri): Promise { + const scmResource = resolveGitResource(uri); + + if (scmResource) { + return await this.open(scmResource); + } + + if (uri.scheme === 'file') { + const uriString = uri.toString(); + const resource = this.model.workingTreeGroup.resources.filter(r => r.uri.toString() === uriString)[0] + || this.model.indexGroup.resources.filter(r => r.uri.toString() === uriString)[0]; + + if (resource) { + return await this.open(resource); + } + } } @command('git.stage') diff --git a/src/vs/editor/browser/widget/diffEditorWidget.ts b/src/vs/editor/browser/widget/diffEditorWidget.ts index 425fc7a0682..636f1472beb 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget.ts @@ -29,6 +29,7 @@ import { Position } from 'vs/editor/common/core/position'; import { Selection } from 'vs/editor/common/core/selection'; import { InlineDecoration } from 'vs/editor/common/viewModel/viewModel'; import { IAddedAction } from 'vs/editor/common/commonCodeEditor'; +import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; interface IEditorDiffDecorations { decorations: editorCommon.IModelDeltaDecoration[]; @@ -213,7 +214,8 @@ export class DiffEditorWidget extends EventEmitter implements editorBrowser.IDif ) { super(); this._editorWorkerService = editorWorkerService; - this._contextKeyService = contextKeyService; + this._contextKeyService = contextKeyService.createScoped(domElement); + this._contextKeyService.createKey('isInDiffEditor', true); this.id = (++DIFF_EDITOR_ID); @@ -289,8 +291,13 @@ export class DiffEditorWidget extends EventEmitter implements editorBrowser.IDif this._lineChanges = null; - this._createLeftHandSideEditor(options, instantiationService); - this._createRightHandSideEditor(options, instantiationService); + const services = new ServiceCollection(); + services.set(IContextKeyService, this._contextKeyService); + + const scopedInstantiationService = instantiationService.createChild(services); + + this._createLeftHandSideEditor(options, scopedInstantiationService); + this._createRightHandSideEditor(options, scopedInstantiationService); if (options.automaticLayout) { this._measureDomElementToken = window.setInterval(() => this._measureDomElement(false), 100);