How to get cursor position in the current editor?

I need the current editor position in the PsiReference.resolve(), PsiReferenceProvider.getReferencesByElement() methods.

I try calculate the position in the code below:
Editor editor = (Editor) DataManager.getInstance().getDataContext().getData(DataConstants.EDITOR);
int offset = editor.getCaretModel().getOffset();

Is there another way (better performance, simpler)?

1 comment

Yes, this is the right way to do it.


Please sign in to leave a comment.