mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 09:08:48 +01:00
ensure (newly) selected item from references tree is visible in the editor (#168574)
fixes https://github.com/microsoft/vscode/issues/167296#event-7989480633
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -126,7 +126,9 @@ export class ReferencesModel implements SymbolItemNavigation<FileItem | Referenc
|
||||
}
|
||||
|
||||
location(item: FileItem | ReferenceItem) {
|
||||
return item instanceof ReferenceItem ? item.location : undefined;
|
||||
return item instanceof ReferenceItem
|
||||
? item.location
|
||||
: new vscode.Location(item.uri, item.references[0]?.location.range ?? new vscode.Position(0, 0));
|
||||
}
|
||||
|
||||
nearest(uri: vscode.Uri, position: vscode.Position): FileItem | ReferenceItem | undefined {
|
||||
|
||||
Reference in New Issue
Block a user