mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00: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:
parent
5d3452353b
commit
a89b0e97a1
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue