void (@NotNull final Project project, @NotNull final Editor editor) { ThreadingAssertions.assertEventDispatchThread(); PsiUtilBase.assertEditorAndProjectConsistent(project, editor); final FindManager findManager = FindManager.getInstance(project); String s = getSelectedText(editor); final FindModel model = findManager.getFindInFileModel().clone(); if (StringUtil.isEmpty(s)) { model.setGlobal(true); } else { if (s.indexOf('\n') >= 0) { model.setGlobal(false); } else { model.setStringToFind(s); model.setGlobal(true); } } model.setReplaceState(false); PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); model.setFindAllEnabled(psiFile != null); findManager.showFindDialog(model, () -> { if (model.isFindAll() && psiFile != null) { findManager.setFindNextModel(model); findAllAndShow(project, psiFile, model); return; } if (!model.isGlobal() && editor.getSelectionModel().hasSelection()) { int offset = model.isForward() ? editor.getSelectionModel().getSelectionStart() : editor.getSelectionModel().getSelectionEnd(); ScrollType scrollType = model.isForward() ? ScrollType.CENTER_DOWN : ScrollType.CENTER_UP; moveCaretAndDontChangeSelection(editor, offset, scrollType); } int offset; if (model.isGlobal()) { if (model.isFromCursor()) { offset = editor.getCaretModel().getOffset(); } else { offset = model.isForward() ? 0 : editor.getDocument().getTextLength(); } } else { // in selection if (!editor.getSelectionModel().hasSelection()) { // TODO[anton] actually, this should never happen - Find dialog should not allow such combination findManager.setFindNextModel(null); return; } offset = model.isForward() ? editor.getSelectionModel().getSelectionStart() : editor.getSelectionModel().getSelectionEnd(); } findManager.setFindNextModel(null); findManager.getFindInFileModel().copyFrom(model); doSearch(project, editor, offset, true, model, true); }); }