From 5c03903da51a2019b56ee334f222e56838c16ed7 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 21 May 2019 19:50:46 -0400 Subject: [PATCH] Ensures uri matches editor before getting a range --- src/commands/copyRemoteFileUrlToClipboard.ts | 9 +++++---- src/commands/openFileInRemote.ts | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/commands/copyRemoteFileUrlToClipboard.ts b/src/commands/copyRemoteFileUrlToClipboard.ts index 140d967..2aead55 100644 --- a/src/commands/copyRemoteFileUrlToClipboard.ts +++ b/src/commands/copyRemoteFileUrlToClipboard.ts @@ -24,10 +24,11 @@ export class CopyRemoteFileUrlToClipboardCommand extends ActiveEditorCommand { } protected preExecute(context: CommandContext, args: CopyRemoteFileUrlToClipboardCommandArgs = { range: true }) { - if (isCommandViewContextWithCommit(context)) { - args = { ...args }; - args.range = false; - args.sha = context.node.commit.sha; + if (context.type === 'uri' || context.type === 'scm-states') { + args = { ...args, range: false }; + } + else if (isCommandViewContextWithCommit(context)) { + args = { ...args, range: false, sha: context.node.commit.sha }; // If it is a StatusFileNode then don't include the sha, since it hasn't been pushed yet if (context.node instanceof StatusFileNode) { diff --git a/src/commands/openFileInRemote.ts b/src/commands/openFileInRemote.ts index 0f80a69..8521951 100644 --- a/src/commands/openFileInRemote.ts +++ b/src/commands/openFileInRemote.ts @@ -16,6 +16,7 @@ import { } from './common'; import { OpenInRemoteCommandArgs } from './openInRemote'; import { Strings } from '../system'; +import { UriComparer } from '../comparers'; export interface OpenFileInRemoteCommandArgs { branch?: string; @@ -58,7 +59,7 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand { try { const remotes = await Container.git.getRemotes(gitUri.repoPath); const range = - args.range && editor != null + args.range && editor != null && UriComparer.equals(editor.document.uri, uri) ? new Range( editor.selection.start.with({ line: editor.selection.start.line + 1 }), editor.selection.end.with({ line: editor.selection.end.line + 1 })