From ebf16df6832391aad9bf01981041a175875ff9a2 Mon Sep 17 00:00:00 2001 From: Eric Gang Date: Tue, 24 Jul 2018 14:26:13 +0800 Subject: [PATCH] Fix a compiler error I didn't notice the preservation should be put under a condition --- extensions/git/src/commands.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 54c8f079a1a..9a104971413 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -230,10 +230,7 @@ export class CommandCenter { } if (!left) { - const previousVisibleRanges = activeTextEditor.visibleRanges; - const document = await workspace.openTextDocument(right); - const editor = await window.showTextDocument(document, opts); - editor.revealRange(previousVisibleRanges[0]); + await commands.executeCommand('vscode.open', right, opts); } else { await commands.executeCommand('vscode.diff', left, right, title, opts); } @@ -574,16 +571,19 @@ export class CommandCenter { viewColumn: ViewColumn.Active }; + const document = await workspace.openTextDocument(uri); + // Check if active text editor has same path as other editor. we cannot compare via // URI.toString() here because the schemas can be different. Instead we just go by path. if (activeTextEditor && activeTextEditor.document.uri.path === uri.path) { + // preserve not only selection but also visible range opts.selection = activeTextEditor.selection; + const previousVisibleRanges = activeTextEditor.visibleRanges; + const editor = await window.showTextDocument(document, opts); + editor.revealRange(previousVisibleRanges[0]); + } else { + await window.showTextDocument(document, opts); } - - const previousVisibleRanges = activeTextEditor.visibleRanges; - const document = await workspace.openTextDocument(uri); - const editor = await window.showTextDocument(document, opts); - editor.revealRange(previousVisibleRanges[0]); } } -- GitLab