diff --git a/src/vs/editor/contrib/referenceSearch/referenceSearch.ts b/src/vs/editor/contrib/referenceSearch/referenceSearch.ts index a745f12aae303abadd638fcc0f07ee9b6bba9c8e..0946a77cdfd309b2cf2b070530e7648ea6c29d74 100644 --- a/src/vs/editor/contrib/referenceSearch/referenceSearch.ts +++ b/src/vs/editor/contrib/referenceSearch/referenceSearch.ts @@ -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), diff --git a/src/vs/editor/contrib/referenceSearch/referencesController.ts b/src/vs/editor/contrib/referenceSearch/referencesController.ts index fd463cf2a95c35e1db4b786b5415ade6ee652c01..69fe4df3ebb21b6f62d074c83fad68b418c275b5 100644 --- a/src/vs/editor/contrib/referenceSearch/referencesController.ts +++ b/src/vs/editor/contrib/referenceSearch/referencesController.ts @@ -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(); diff --git a/src/vs/editor/contrib/referenceSearch/referencesModel.ts b/src/vs/editor/contrib/referenceSearch/referencesModel.ts index 6347686bee648db02971db57221b1eb7e0959024..88880e33a9711e7f00b1f5324204377ff0f85aa7 100644 --- a/src/vs/editor/contrib/referenceSearch/referencesModel.ts +++ b/src/vs/editor/contrib/referenceSearch/referencesModel.ts @@ -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; - idx = reference.parent.parent.groups.indexOf(reference.parent); - idx = (idx + 1) % totalLength; + 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]; + } - 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 {