From a89b0e97a1a23de931694d7d87b3879c3b00fd1e Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Fri, 9 Dec 2022 13:31:54 +0100 Subject: [PATCH] ensure (newly) selected item from references tree is visible in the editor (#168574) fixes https://github.com/microsoft/vscode/issues/167296#event-7989480633 --- extensions/references-view/src/navigation.ts | 15 +++++++++++++++ .../references-view/src/references/model.ts | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/extensions/references-view/src/navigation.ts b/extensions/references-view/src/navigation.ts index e592dfbf7ea..fdb7dc64881 100644 --- a/extensions/references-view/src/navigation.ts +++ b/extensions/references-view/src/navigation.ts @@ -18,6 +18,7 @@ export class Navigation { this._disposables.push( vscode.commands.registerCommand('references-view.next', () => this.next(false)), vscode.commands.registerCommand('references-view.prev', () => this.previous(false)), + _view.onDidChangeSelection(() => this._ensureSelectedElementIsVisible()), ); } @@ -30,6 +31,20 @@ export class Navigation { this._ctxCanNavigate.set(Boolean(this._delegate)); } + private _ensureSelectedElementIsVisible(): void { + if (this._view.selection.length === 0) { + return; + } + const [item] = this._view.selection; + const location = this._delegate?.location(item); + if (!location) { + return; + } + if (vscode.window.activeTextEditor?.document.uri.toString() !== location.uri.toString()) { + this._open(location, true); + } + } + private _anchor(): undefined | unknown { if (!this._delegate) { return undefined; diff --git a/extensions/references-view/src/references/model.ts b/extensions/references-view/src/references/model.ts index 83978565f20..19bac0047d9 100644 --- a/extensions/references-view/src/references/model.ts +++ b/extensions/references-view/src/references/model.ts @@ -126,7 +126,9 @@ export class ReferencesModel implements SymbolItemNavigation