This commit is contained in:
Henning Dieterichs 2024-02-23 18:14:21 +01:00 committed by GitHub
parent cdb1a962cc
commit 12997e68fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
}
}
}