From 14a12b8bb5e44686dc9bd5e70570b90f9c52759f Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 29 Aug 2022 16:38:22 -0400 Subject: [PATCH] Updates Show Commit Details command to open view --- package.json | 23 +++++++++++----------- src/commands/showCommitsInView.ts | 21 +++++++++++++++++++- src/webviews/apps/settings/partials/code-lens.html | 10 +++++----- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 3c7c0d8..588e887 100644 --- a/package.json +++ b/package.json @@ -381,7 +381,7 @@ "Toggles file changes from the commit", "Compares the current committed file with the previous commit", "Reveals the commit in the Side Bar", - "Searches for the commit", + "Shows the commit details", "Shows a commit details quick pick menu", "Shows a commit file details quick pick menu", "Shows a file history quick pick menu", @@ -548,7 +548,7 @@ "Compares the current line commit with the previous", "Compares the current line commit with the working tree", "Reveals the commit in the Side Bar", - "Searches for the commit", + "Shows the commit details", "Shows a commit details quick pick menu", "Shows a commit file details quick pick menu", "Shows a file history quick pick menu", @@ -4446,8 +4446,9 @@ }, { "command": "gitlens.showCommitInView", - "title": "Search for Commit in Side Bar", - "category": "GitLens" + "title": "Show Commit Details", + "category": "GitLens", + "icon": "$(eye)" }, { "command": "gitlens.showCommitsInView", @@ -9462,10 +9463,9 @@ "group": "2_gitlens_quickopen@1" }, { - "command": "gitlens.openCommitOnRemote", - "when": "viewItem =~ /gitlens:commit\\b/ && gitlens:hasRemotes", - "group": "3_gitlens_explore@0", - "alt": "gitlens.copyRemoteCommitUrl" + "command": "gitlens.showCommitInView", + "when": "viewItem =~ /gitlens:commit\\b/", + "group": "3_gitlens_explore@0" }, { "command": "gitlens.revealCommitInView", @@ -9473,9 +9473,10 @@ "group": "3_gitlens_explore@1" }, { - "command": "gitlens.showCommitInView", - "when": "viewItem =~ /gitlens:commit\\b/", - "group": "3_gitlens_explore@2" + "command": "gitlens.openCommitOnRemote", + "when": "viewItem =~ /gitlens:commit\\b/ && gitlens:hasRemotes", + "group": "3_gitlens_explore@2", + "alt": "gitlens.copyRemoteCommitUrl" }, { "submenu": "gitlens/commit/copy", diff --git a/src/commands/showCommitsInView.ts b/src/commands/showCommitsInView.ts index e681db5..777965f 100644 --- a/src/commands/showCommitsInView.ts +++ b/src/commands/showCommitsInView.ts @@ -8,7 +8,8 @@ import { Logger } from '../logger'; import { showFileNotUnderSourceControlWarningMessage, showGenericErrorMessage } from '../messages'; import { command } from '../system/command'; import { filterMap } from '../system/iterable'; -import { ActiveEditorCommand, getCommandUri } from './base'; +import type { CommandContext } from './base'; +import { ActiveEditorCommand, getCommandUri, isCommandContextViewNodeHasCommit } from './base'; export interface ShowCommitsInViewCommandArgs { refs?: string[]; @@ -21,6 +22,18 @@ export class ShowCommitsInViewCommand extends ActiveEditorCommand { super([Commands.ShowCommitInView, Commands.ShowCommitsInView]); } + protected override preExecute(context: CommandContext, args?: ShowCommitsInViewCommandArgs) { + if (context.type === 'viewItem') { + args = { ...args }; + if (isCommandContextViewNodeHasCommit(context)) { + args.refs = [context.node.commit.sha]; + args.repoPath = context.node.commit.repoPath; + } + } + + return this.execute(context.editor, context.uri, args); + } + async execute(editor?: TextEditor, uri?: Uri, args?: ShowCommitsInViewCommandArgs) { args = { ...args }; @@ -58,6 +71,12 @@ export class ShowCommitsInViewCommand extends ActiveEditorCommand { } } + if (args.refs.length === 1) { + return this.container.commitDetailsView.show({ + commit: { ref: args.refs[0], refType: 'revision', repoPath: args.repoPath!, name: '' }, + }); + } + return executeGitCommand({ command: 'search', state: { diff --git a/src/webviews/apps/settings/partials/code-lens.html b/src/webviews/apps/settings/partials/code-lens.html index d86c89d..7f989e5 100644 --- a/src/webviews/apps/settings/partials/code-lens.html +++ b/src/webviews/apps/settings/partials/code-lens.html @@ -80,12 +80,12 @@ - +