From 12997e68fd1620ff0cb2cbfae3f7390a0c1e9e13 Mon Sep 17 00:00:00 2001 From: Henning Dieterichs Date: Fri, 23 Feb 2024 18:14:21 +0100 Subject: [PATCH] Fixes #196084 (#206100) --- extensions/git/src/commands.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 7f7f769fec5..01a8434c448 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1194,7 +1194,7 @@ export class CommandCenter { const activeTextEditor = window.activeTextEditor; // Must extract these now because opening a new document will change the activeTextEditor reference - const previousVisibleRange = activeTextEditor?.visibleRanges[0]; + const previousVisibleRanges = activeTextEditor?.visibleRanges; const previousURI = activeTextEditor?.document.uri; const previousSelection = activeTextEditor?.selection; @@ -1225,8 +1225,13 @@ export class CommandCenter { opts.selection = previousSelection; const editor = await window.showTextDocument(document, opts); // This should always be defined but just in case - if (previousVisibleRange) { - editor.revealRange(previousVisibleRange); + if (previousVisibleRanges && previousVisibleRanges.length > 0) { + let rangeToReveal = previousVisibleRanges[0]; + if (previousSelection && previousVisibleRanges.length > 1) { + // In case of multiple visible ranges, find the one that intersects with the selection + rangeToReveal = previousVisibleRanges.find(r => r.intersection(previousSelection)) ?? rangeToReveal; + } + editor.revealRange(rangeToReveal); } } }