Search in sources :

Example 11 with EditorWindow

use of com.intellij.injected.editor.EditorWindow in project intellij-plugins by JetBrains.

the class FlexIntroduceConstantTest method doTest.

private void doTest(final JSIntroduceConstantHandler handler, String fileName, String ext) throws Exception {
    configureByFile(fileName + "." + ext);
    Editor injectedEditor = BaseCodeInsightAction.getInjectedEditor(myProject, myEditor);
    if (injectedEditor != null) {
        myEditor = injectedEditor;
        myFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
    }
    handler.invoke(getProject(), getEditor(), getFile(), null);
    if (injectedEditor instanceof EditorWindow) {
        myEditor = ((EditorWindow) injectedEditor).getDelegate();
        myFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
    }
    checkResultByFile(fileName + "_after." + ext);
}
Also used : Editor(com.intellij.openapi.editor.Editor) EditorWindow(com.intellij.injected.editor.EditorWindow)

Example 12 with EditorWindow

use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.

the class ShowIntentionActionsHandler method invoke.

@Override
public void invoke(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file) {
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    if (editor instanceof EditorWindow) {
        editor = ((EditorWindow) editor).getDelegate();
        file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
    }
    final LookupEx lookup = LookupManager.getActiveLookup(editor);
    if (lookup != null) {
        lookup.showElementActions();
        return;
    }
    final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(project);
    letAutoImportComplete(editor, file, codeAnalyzer);
    ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo();
    ShowIntentionsPass.getActionsToShow(editor, file, intentions, -1);
    IntentionHintComponent hintComponent = codeAnalyzer.getLastIntentionHint();
    if (hintComponent != null) {
        IntentionHintComponent.PopupUpdateResult result = hintComponent.isForEditor(editor) ? hintComponent.updateActions(intentions) : IntentionHintComponent.PopupUpdateResult.HIDE_AND_RECREATE;
        if (result == IntentionHintComponent.PopupUpdateResult.HIDE_AND_RECREATE) {
            hintComponent.hide();
        }
    }
    if (HintManagerImpl.getInstanceImpl().performCurrentQuestionAction())
        return;
    //intentions check isWritable before modification: if (!file.isWritable()) return;
    TemplateState state = TemplateManagerImpl.getTemplateState(editor);
    if (state != null && !state.isFinished()) {
        return;
    }
    if (!intentions.isEmpty()) {
        IntentionHintComponent.showIntentionHint(project, file, editor, intentions, true);
    }
}
Also used : ShowIntentionsPass(com.intellij.codeInsight.daemon.impl.ShowIntentionsPass) DaemonCodeAnalyzerImpl(com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl) LookupEx(com.intellij.codeInsight.lookup.LookupEx) TemplateState(com.intellij.codeInsight.template.impl.TemplateState) EditorWindow(com.intellij.injected.editor.EditorWindow)

Example 13 with EditorWindow

use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.

the class ParameterInfoController method showHint.

public void showHint(boolean requestFocus) {
    Pair<Point, Short> pos = myProvider.getBestPointPosition(myHint, myComponent.getParameterOwner(), myLbraceMarker.getStartOffset(), true, HintManager.UNDER);
    HintHint hintHint = HintManagerImpl.createHintHint(myEditor, pos.getFirst(), myHint, pos.getSecond());
    hintHint.setExplicitClose(true);
    hintHint.setRequestFocus(requestFocus);
    Editor editorToShow = myEditor instanceof EditorWindow ? ((EditorWindow) myEditor).getDelegate() : myEditor;
    // is case of injection we need to calculate position for EditorWindow
    // also we need to show the hint in the main editor because of intention bulb
    HintManagerImpl.getInstanceImpl().showEditorHint(myHint, editorToShow, pos.getFirst(), HintManager.HIDE_BY_ESCAPE | HintManager.UPDATE_BY_SCROLLING, 0, false, hintHint);
    updateComponent();
}
Also used : HintHint(com.intellij.ui.HintHint) EditorWindow(com.intellij.injected.editor.EditorWindow)

Example 14 with EditorWindow

use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.

the class HighlightUsagesHandler method isClearHighlights.

public static boolean isClearHighlights(@NotNull Editor editor) {
    if (editor instanceof EditorWindow)
        editor = ((EditorWindow) editor).getDelegate();
    RangeHighlighter[] highlighters = ((HighlightManagerImpl) HighlightManager.getInstance(editor.getProject())).getHighlighters(editor);
    int caretOffset = editor.getCaretModel().getOffset();
    for (RangeHighlighter highlighter : highlighters) {
        if (TextRange.create(highlighter).grown(1).contains(caretOffset)) {
            return true;
        }
    }
    return false;
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) EditorWindow(com.intellij.injected.editor.EditorWindow)

Example 15 with EditorWindow

use of com.intellij.injected.editor.EditorWindow 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)

Aggregations

EditorWindow (com.intellij.injected.editor.EditorWindow)44 Editor (com.intellij.openapi.editor.Editor)15 TextRange (com.intellij.openapi.util.TextRange)10 Project (com.intellij.openapi.project.Project)9 Document (com.intellij.openapi.editor.Document)8 PsiFile (com.intellij.psi.PsiFile)8 NotNull (org.jetbrains.annotations.NotNull)8 PsiElement (com.intellij.psi.PsiElement)7 com.intellij.openapi.fileEditor (com.intellij.openapi.fileEditor)5 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)4 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)3 EditorEx (com.intellij.openapi.editor.ex.EditorEx)3 LexerEditorHighlighter (com.intellij.openapi.editor.ex.util.LexerEditorHighlighter)3 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)3 ArrayList (java.util.ArrayList)3 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)2 DocumentWindow (com.intellij.injected.editor.DocumentWindow)2 InjectedCaret (com.intellij.injected.editor.InjectedCaret)2 SimpleDataContext (com.intellij.openapi.actionSystem.impl.SimpleDataContext)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2