diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 54c8f079a1a1ba64d1471d16bdce584d844d5053..9a10497141389e097b2f428212daa6a5c444f600 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]); } }