mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
add goto next/prev reference command, #44414
This commit is contained in:
parent
6c8b65d1e8
commit
055ac07ca7
|
@ -194,6 +194,30 @@ function withController(accessor: ServicesAccessor, fn: (controller: ReferencesC
|
|||
fn(controller);
|
||||
}
|
||||
|
||||
KeybindingsRegistry.registerCommandAndKeybindingRule({
|
||||
id: 'goToNextReference',
|
||||
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(50),
|
||||
primary: KeyCode.F4,
|
||||
when: ctxReferenceSearchVisible,
|
||||
handler(accessor) {
|
||||
withController(accessor, controller => {
|
||||
controller.goToNextOrPreviousReference(true);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
KeybindingsRegistry.registerCommandAndKeybindingRule({
|
||||
id: 'goToPreviousReference',
|
||||
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(50),
|
||||
primary: KeyMod.Shift | KeyCode.F4,
|
||||
when: ctxReferenceSearchVisible,
|
||||
handler(accessor) {
|
||||
withController(accessor, controller => {
|
||||
controller.goToNextOrPreviousReference(false);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
KeybindingsRegistry.registerCommandAndKeybindingRule({
|
||||
id: 'closeReferenceSearch',
|
||||
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(50),
|
||||
|
|
|
@ -174,6 +174,13 @@ export class ReferencesController implements editorCommon.IEditorContribution {
|
|||
});
|
||||
}
|
||||
|
||||
public goToNextOrPreviousReference(fwd: boolean) {
|
||||
let source = this._model.nearestReference(this._editor.getModel().uri, this._widget.position);
|
||||
let target = this._model.nextOrPreviousReference(source, fwd);
|
||||
this._gotoReference(target);
|
||||
this._editor.focus();
|
||||
}
|
||||
|
||||
public closeWidget(): void {
|
||||
if (this._widget) {
|
||||
this._widget.dispose();
|
||||
|
|
|
@ -253,20 +253,32 @@ export class ReferencesModel implements IDisposable {
|
|||
}
|
||||
}
|
||||
|
||||
public nextReference(reference: OneReference): OneReference {
|
||||
public nextOrPreviousReference(reference: OneReference, next: boolean): OneReference {
|
||||
|
||||
var idx = reference.parent.children.indexOf(reference),
|
||||
len = reference.parent.children.length,
|
||||
totalLength = reference.parent.parent.groups.length;
|
||||
let { parent } = reference;
|
||||
|
||||
if (idx + 1 < len || totalLength === 1) {
|
||||
return reference.parent.children[(idx + 1) % len];
|
||||
let idx = parent.children.indexOf(reference);
|
||||
let childCount = parent.children.length;
|
||||
let groupCount = parent.parent.groups.length;
|
||||
|
||||
if (groupCount === 1 || next && idx + 1 < childCount || !next && idx > 1) {
|
||||
// cycling within one file
|
||||
if (next) {
|
||||
idx = (idx + 1) % childCount;
|
||||
} else {
|
||||
idx = (idx + childCount - 1) % childCount;
|
||||
}
|
||||
return parent.children[idx];
|
||||
}
|
||||
|
||||
idx = reference.parent.parent.groups.indexOf(reference.parent);
|
||||
idx = (idx + 1) % totalLength;
|
||||
|
||||
return reference.parent.parent.groups[idx].children[0];
|
||||
idx = parent.parent.groups.indexOf(parent);
|
||||
if (next) {
|
||||
idx = (idx + 1) % groupCount;
|
||||
return parent.parent.groups[idx].children[0];
|
||||
} else {
|
||||
idx = (idx + groupCount - 1) % groupCount;
|
||||
return parent.parent.groups[idx].children[parent.parent.groups[idx].children.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
public nearestReference(resource: URI, position: Position): OneReference {
|
||||
|
|
Loading…
Reference in a new issue