From 8ce9f543a21d65ef414066b5634d45ddcbb26616 Mon Sep 17 00:00:00 2001 From: Keith Daulton Date: Mon, 13 Mar 2023 16:36:37 -0400 Subject: [PATCH] Adds support for sidebar views --- package.json | 15 ++++++++++----- src/commands/copyRelativePathToClipboard.ts | 16 +++++++++++++--- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index bd621da..b67ff6e 100644 --- a/package.json +++ b/package.json @@ -9360,19 +9360,19 @@ "group": "1_gitlens@3" }, { - "command": "gitlens.copyShaToClipboard", + "command": "gitlens.copyRelativePathToClipboard", "when": "editorTextFocus && gitlens:activeFileStatus =~ /blameable/ && config.gitlens.menus.editor.clipboard", - "group": "2_gitlens@1" + "group": "1_gitlens@4" }, { - "command": "gitlens.copyRelativePathToClipboard", + "command": "gitlens.copyShaToClipboard", "when": "editorTextFocus && gitlens:activeFileStatus =~ /blameable/ && config.gitlens.menus.editor.clipboard", - "group": "2_gitlens@2" + "group": "2_gitlens@1" }, { "command": "gitlens.copyMessageToClipboard", "when": "editorTextFocus && gitlens:activeFileStatus =~ /blameable/ && config.gitlens.menus.editor.clipboard", - "group": "2_gitlens@3" + "group": "2_gitlens@2" } ], "editor/title": [ @@ -12098,6 +12098,11 @@ "group": "2_gitlens@2" }, { + "command": "gitlens.copyRelativePathToClipboard", + "when": "viewItem =~ /gitlens:(file)\\b/", + "group": "2_gitlens@3" + }, + { "command": "gitlens.graph.copySha", "when": "webviewItem =~ /gitlens:(?!stash\\b)/", "group": "1_gitlens@1" diff --git a/src/commands/copyRelativePathToClipboard.ts b/src/commands/copyRelativePathToClipboard.ts index 321b774..5154a8f 100644 --- a/src/commands/copyRelativePathToClipboard.ts +++ b/src/commands/copyRelativePathToClipboard.ts @@ -1,8 +1,10 @@ -import { env, TextEditor, Uri } from 'vscode'; +import type { TextEditor, Uri } from 'vscode'; +import { env } from 'vscode'; import { Commands } from '../constants'; import type { Container } from '../container'; import { command } from '../system/command'; -import { ActiveEditorCommand, getCommandUri } from './base'; +import type { CommandContext } from './base'; +import { ActiveEditorCommand, getCommandUri, isCommandContextViewNodeHasFileCommit } from './base'; @command() export class CopyRelativePathToClipboardCommand extends ActiveEditorCommand { @@ -10,6 +12,14 @@ export class CopyRelativePathToClipboardCommand extends ActiveEditorCommand { super(Commands.CopyRelativePathToClipboard); } + protected override preExecute(context: CommandContext) { + if (isCommandContextViewNodeHasFileCommit(context)) { + return this.execute(context.editor, context.node.commit.file!.uri); + } + + return this.execute(context.editor, context.uri); + } + async execute(editor?: TextEditor, uri?: Uri) { uri = getCommandUri(uri, editor); let relativePath = ''; @@ -20,7 +30,7 @@ export class CopyRelativePathToClipboardCommand extends ActiveEditorCommand { } } - void (await env.clipboard.writeText(relativePath)); + await env.clipboard.writeText(relativePath); return undefined; } }