void (@NotNull final Editor editor, @Nullable Caret c, DataContext dataContext) { Caret caret = c == null ? editor.getCaretModel().getPrimaryCaret() : c; boolean wholeWordsSearch = false; if (!caret.hasSelection()) { TextRange wordSelectionRange = getSelectionRange(editor, caret); if (wordSelectionRange != null) { setSelection(editor, caret, wordSelectionRange); wholeWordsSearch = true; } } String selectedText = caret.getSelectedText(); Project project = editor.getProject(); if (project == null || selectedText == null) { return; } int caretShiftFromSelectionStart = caret.getOffset() - caret.getSelectionStart(); final FindManager findManager = FindManager.getInstance(project); final FindModel model = getFindModel(selectedText, wholeWordsSearch); FindUtil.selectSearchResultsInEditor(editor, new Iterator<>() { FindResult findResult = findManager.findString(editor.getDocument().getCharsSequence(), 0, model); @Override public boolean hasNext() { return findResult.isStringFound(); } @Override public FindResult next() { FindResult result = findResult; findResult = findManager.findString(editor.getDocument().getCharsSequence(), findResult.getEndOffset(), model); return result; } @Override public void remove() { throw new UnsupportedOperationException(); } }, caretShiftFromSelectionStart); editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); }