Search in sources :

Example 1 with EditorSearchSession

use of com.intellij.find.EditorSearchSession in project intellij-community by JetBrains.

the class HighlightUsagesHandler method doRangeHighlighting.

private static void doRangeHighlighting(Editor editor, Project project) {
    if (!editor.getSelectionModel().hasSelection())
        return;
    final String text = editor.getSelectionModel().getSelectedText();
    if (text == null)
        return;
    if (editor instanceof EditorWindow) {
        // highlight selection in the whole editor, not injected fragment only
        editor = ((EditorWindow) editor).getDelegate();
    }
    EditorSearchSession oldSearch = EditorSearchSession.get(editor);
    if (oldSearch != null) {
        if (oldSearch.hasMatches()) {
            String oldText = oldSearch.getTextInField();
            if (!oldSearch.getFindModel().isRegularExpressions()) {
                oldText = StringUtil.escapeToRegexp(oldText);
                oldSearch.getFindModel().setRegularExpressions(true);
            }
            String newText = oldText + '|' + StringUtil.escapeToRegexp(text);
            oldSearch.setTextInField(newText);
            return;
        }
    }
    EditorSearchSession.start(editor, project).getFindModel().setRegularExpressions(false);
}
Also used : EditorSearchSession(com.intellij.find.EditorSearchSession) EditorWindow(com.intellij.injected.editor.EditorWindow)

Example 2 with EditorSearchSession

use of com.intellij.find.EditorSearchSession in project intellij-community by JetBrains.

the class FindAllAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    Editor editor = e.getRequiredData(CommonDataKeys.EDITOR_EVEN_IF_INACTIVE);
    Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    EditorSearchSession search = e.getRequiredData(EditorSearchSession.SESSION_KEY);
    if (project.isDisposed())
        return;
    FindModel oldModel = FindManager.getInstance(project).getFindInFileModel();
    FindModel newModel = oldModel.clone();
    String text = search.getTextInField();
    if (StringUtil.isEmpty(text))
        return;
    newModel.setStringToFind(text);
    FindUtil.findAllAndShow(project, editor, newModel);
}
Also used : Project(com.intellij.openapi.project.Project) FindModel(com.intellij.find.FindModel) EditorSearchSession(com.intellij.find.EditorSearchSession) Editor(com.intellij.openapi.editor.Editor)

Example 3 with EditorSearchSession

use of com.intellij.find.EditorSearchSession in project intellij-community by JetBrains.

the class RestorePreviousSettingsAction method update.

@Override
public void update(AnActionEvent e) {
    Project project = e.getProject();
    EditorSearchSession search = e.getData(EditorSearchSession.SESSION_KEY);
    e.getPresentation().setEnabled(project != null && search != null && !project.isDisposed() && search.getTextInField().isEmpty() && FindManager.getInstance(project).getPreviousFindModel() != null);
}
Also used : Project(com.intellij.openapi.project.Project) EditorSearchSession(com.intellij.find.EditorSearchSession)

Example 4 with EditorSearchSession

use of com.intellij.find.EditorSearchSession in project intellij-community by JetBrains.

the class SelectAllAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    EditorSearchSession search = e.getRequiredData(EditorSearchSession.SESSION_KEY);
    search.selectAllOccurrences();
    search.close();
}
Also used : EditorSearchSession(com.intellij.find.EditorSearchSession)

Example 5 with EditorSearchSession

use of com.intellij.find.EditorSearchSession in project intellij-community by JetBrains.

the class SwitchToFind method update.

@Override
public void update(AnActionEvent e) {
    if (KeymapUtil.isEmacsKeymap()) {
        // Emacs users are accustomed to the editor that executes 'find next' on subsequent pressing of shortcut that
        // activates 'incremental search'. Hence, we do the similar hack here for them.
        ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_NEXT).update(e);
    } else {
        EditorSearchSession search = e.getData(EditorSearchSession.SESSION_KEY);
        e.getPresentation().setEnabledAndVisible(search != null);
    }
}
Also used : EditorSearchSession(com.intellij.find.EditorSearchSession)

Aggregations

EditorSearchSession (com.intellij.find.EditorSearchSession)12 FindModel (com.intellij.find.FindModel)4 Editor (com.intellij.openapi.editor.Editor)3 Project (com.intellij.openapi.project.Project)3 EditorWindow (com.intellij.injected.editor.EditorWindow)1