diff --git a/src/views/nodes/commitFileNode.ts b/src/views/nodes/commitFileNode.ts index 7dd8975..f1d976d 100644 --- a/src/views/nodes/commitFileNode.ts +++ b/src/views/nodes/commitFileNode.ts @@ -203,7 +203,7 @@ export class CommitFileNode extends ViewRefFileNode { }, }; return { - title: 'Compare File with Previous Revision', + title: 'Open Changes with Previous Revision', command: Commands.DiffWithPrevious, arguments: [GitUri.fromFile(this.file, this.commit.repoPath), commandArgs], }; diff --git a/src/views/nodes/commitNode.ts b/src/views/nodes/commitNode.ts index 03a6848..f8fd58e 100644 --- a/src/views/nodes/commitNode.ts +++ b/src/views/nodes/commitNode.ts @@ -110,7 +110,7 @@ export class CommitNode extends ViewRefNode { }, }; return { - title: 'Compare File with Previous Revision', + title: 'Open Changes with Previous Revision', command: Commands.DiffWithPrevious, arguments: [this.uri, commandArgs], }; diff --git a/src/views/nodes/resultsFileNode.ts b/src/views/nodes/resultsFileNode.ts index 988760e..8ce9ca8 100644 --- a/src/views/nodes/resultsFileNode.ts +++ b/src/views/nodes/resultsFileNode.ts @@ -127,7 +127,7 @@ export class ResultsFileNode extends ViewRefFileNode { return { title: 'Open Changes', command: Commands.DiffWith, - arguments: [this.uri, commandArgs], + arguments: [commandArgs], }; } } diff --git a/src/views/nodes/statusFileNode.ts b/src/views/nodes/statusFileNode.ts index cf3fe43..2fcccd6 100644 --- a/src/views/nodes/statusFileNode.ts +++ b/src/views/nodes/statusFileNode.ts @@ -232,7 +232,7 @@ export class StatusFileNode extends ViewNode { }, }; return { - title: 'Compare File with Previous Revision', + title: 'Open Changes with Previous Revision', command: Commands.DiffWithPrevious, arguments: [GitUri.fromFile(this.file, this.repoPath), commandArgs], }; diff --git a/src/views/viewCommands.ts b/src/views/viewCommands.ts index 178b57b..c91305d 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -5,6 +5,8 @@ import { DiffWithCommandArgs, DiffWithPreviousCommandArgs, DiffWithWorkingCommandArgs, + executeCommand, + executeEditorCommand, findOrOpenEditor, GitActions, OpenFileAtRevisionCommandArgs, @@ -571,7 +573,7 @@ export class ViewCommands { this._selectedFile = undefined; void setCommandContext(CommandContext.ViewsCanCompareFile, false); - const diffArgs: DiffWithCommandArgs = { + return executeCommand(Commands.DiffWith, { repoPath: selected.repoPath, lhs: { sha: selected.ref, @@ -581,8 +583,7 @@ export class ViewCommands { sha: node.ref, uri: node.uri, }, - }; - return commands.executeCommand(Commands.DiffWith, diffArgs); + }); } private _selectedFile: CompareSelectedInfo | undefined; @@ -625,14 +626,27 @@ export class ViewCommands { @debug() private openChanges(node: ViewRefFileNode | StatusFileNode) { - if (!(node instanceof ViewRefFileNode) && !(node instanceof StatusFileNode)) return undefined; + if (!(node instanceof ViewRefFileNode) && !(node instanceof StatusFileNode)) return; const command = node.getCommand(); - if (command === undefined || command.arguments === undefined) return undefined; - - const [uri, args] = command.arguments as [Uri, DiffWithPreviousCommandArgs]; - args.showOptions!.preview = false; - return commands.executeCommand(command.command, uri, args); + if (command?.arguments == null) return; + + switch (command.command) { + case Commands.DiffWith: { + const [args] = command.arguments as [DiffWithCommandArgs]; + args.showOptions!.preview = false; + void executeCommand(command.command, args); + break; + } + case Commands.DiffWithPrevious: { + const [uri, args] = command.arguments as [Uri, DiffWithPreviousCommandArgs]; + args.showOptions!.preview = false; + void executeEditorCommand(command.command, uri, args); + break; + } + default: + throw new Error(`Unexpected command: ${command.command}`); + } // TODO@eamodio Revisit this // return GitActions.Commit.openChanges(node.file, node instanceof ViewRefFileNode ? node.ref : node.commit, {