From d2a5141743e1108fc547cdc06baa7047d9000481 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 22 Jun 2021 00:43:22 -0400 Subject: [PATCH] Closes #1529: adds diff previous w/ working --- CHANGELOG.md | 1 + package.json | 28 +++++++++++++++++++++------- src/views/viewCommands.ts | 15 +++++++++++++++ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8579ef4..b6a23a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Added +- Adds new _Open Previous Changes with Working File_ command to commit files in views — closes [#1529](https://github.com/eamodio/vscode-gitlens/issues/1529) - Adopts new vscode `createStatusBarItem` API to allow for independent toggling — closes [#1543](https://github.com/eamodio/vscode-gitlens/issues/1543) ### Fixed diff --git a/package.json b/package.json index c6ce0b5..ece0878 100644 --- a/package.json +++ b/package.json @@ -4125,6 +4125,11 @@ } }, { + "command": "gitlens.views.openPreviousChangesWithWorking", + "title": "Open Previous Changes with Working File", + "category": "GitLens" + }, + { "command": "gitlens.views.openFile", "title": "Open File", "category": "GitLens", @@ -5829,6 +5834,10 @@ "when": "false" }, { + "command": "gitlens.views.openPreviousChangesWithWorking", + "when": "false" + }, + { "command": "gitlens.views.openFile", "when": "false" }, @@ -8835,32 +8844,37 @@ ], "gitlens/commit/file/changes": [ { - "command": "gitlens.externalDiff", + "command": "gitlens.views.openChangesWithWorking", "when": "viewItem =~ /gitlens:file\\b(?!.*?\\b\\+conflicted\\b)/", "group": "1_gitlens@1" }, { - "command": "gitlens.views.openChangesWithWorking", - "whsen": "viewItem =~ /gitlens:file\\b(?!.*?\\b\\+conflicted\\b)/", + "command": "gitlens.views.openPreviousChangesWithWorking", + "when": "viewItem =~ /gitlens:file\\b(?!.*?\\b\\+(conflicted|stashed|staged|unstaged)\\b)/", "group": "1_gitlens@2" }, { "command": "gitlens.diffWithRevision", - "group": "2_gitlens@1" + "group": "1_gitlens@3" }, { "command": "gitlens.diffWithRevisionFrom", - "group": "2_gitlens@2" + "group": "1_gitlens@4" + }, + { + "command": "gitlens.externalDiff", + "when": "viewItem =~ /gitlens:file\\b(?!.*?\\b\\+conflicted\\b)/", + "group": "1_gitlens@5" }, { "command": "gitlens.views.highlightChanges", "when": "viewItem =~ /gitlens:file\\b((?=.*?\\b\\+(committed|stashed)\\b)|:results)/", - "group": "3_gitlens@1" + "group": "2_gitlens@1" }, { "command": "gitlens.views.highlightRevisionChanges", "when": "viewItem =~ /gitlens:file\\b((?=.*?\\b\\+committed\\b)|:results)/", - "group": "3_gitlens@2" + "group": "2_gitlens@2" } ], "gitlens/editor/annotations": [ diff --git a/src/views/viewCommands.ts b/src/views/viewCommands.ts index a8c15ee..380e46d 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -153,6 +153,11 @@ export class ViewCommands { commands.registerCommand('gitlens.views.openChanges', this.openChanges, this); commands.registerCommand('gitlens.views.openChangesWithWorking', this.openChangesWithWorking, this); + commands.registerCommand( + 'gitlens.views.openPreviousChangesWithWorking', + this.openPreviousChangesWithWorking, + this, + ); commands.registerCommand('gitlens.views.openFile', this.openFile, this); commands.registerCommand('gitlens.views.openFileRevision', this.openRevision, this); commands.registerCommand('gitlens.views.openChangedFiles', this.openFiles, this); @@ -1008,6 +1013,16 @@ export class ViewCommands { } @debug() + private async openPreviousChangesWithWorking(node: ViewRefFileNode) { + if (!(node instanceof ViewRefFileNode)) return Promise.resolve(); + + return GitActions.Commit.openChangesWithWorking(node.file, { + repoPath: node.repoPath, + ref: `${node.ref.ref}^`, + }); + } + + @debug() private openFile( node: ViewRefFileNode | MergeConflictFileNode | StatusFileNode | FileHistoryNode | LineHistoryNode, options?: TextDocumentShowOptions,