Search in sources :

Example 6 with EditorWindow

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

the class LightPlatformCodeInsightTestCase method bringRealEditorBack.

protected static void bringRealEditorBack() {
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    if (myEditor instanceof EditorWindow) {
        Document document = ((DocumentWindow) myEditor.getDocument()).getDelegate();
        myFile = PsiDocumentManager.getInstance(getProject()).getPsiFile(document);
        myEditor = ((EditorWindow) myEditor).getDelegate();
        myVFile = myFile.getVirtualFile();
    }
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) Document(com.intellij.openapi.editor.Document) EditorWindow(com.intellij.injected.editor.EditorWindow)

Example 7 with EditorWindow

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

the class LightPlatformCodeInsightTestCase method setupEditorForInjectedLanguage.

private static void setupEditorForInjectedLanguage() {
    if (myEditor != null) {
        final Ref<EditorWindow> editorWindowRef = new Ref<>();
        myEditor.getCaretModel().runForEachCaret(caret -> {
            Editor editor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(myEditor, myFile);
            if (caret == myEditor.getCaretModel().getPrimaryCaret() && editor instanceof EditorWindow) {
                editorWindowRef.set((EditorWindow) editor);
            }
        });
        if (!editorWindowRef.isNull()) {
            myEditor = editorWindowRef.get();
            myFile = editorWindowRef.get().getInjectedFile();
        }
    }
}
Also used : Ref(com.intellij.openapi.util.Ref) Editor(com.intellij.openapi.editor.Editor) EditorWindow(com.intellij.injected.editor.EditorWindow)

Example 8 with EditorWindow

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

the class CodeInsightTestUtil method doInlineRename.

@TestOnly
public static void doInlineRename(VariableInplaceRenameHandler handler, final String newName, @NotNull Editor editor, PsiElement elementAtCaret) {
    Project project = editor.getProject();
    TemplateManagerImpl templateManager = (TemplateManagerImpl) TemplateManager.getInstance(project);
    try {
        templateManager.setTemplateTesting(true);
        handler.doRename(elementAtCaret, editor, DataManager.getInstance().getDataContext(editor.getComponent()));
        if (editor instanceof EditorWindow) {
            editor = ((EditorWindow) editor).getDelegate();
        }
        TemplateState state = TemplateManagerImpl.getTemplateState(editor);
        assert state != null;
        final TextRange range = state.getCurrentVariableRange();
        assert range != null;
        final Editor finalEditor = editor;
        new WriteCommandAction.Simple(project) {

            @Override
            protected void run() throws Throwable {
                finalEditor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), newName);
            }
        }.execute().throwException();
        state = TemplateManagerImpl.getTemplateState(editor);
        assert state != null;
        state.gotoEnd(false);
    } finally {
        templateManager.setTemplateTesting(false);
    }
}
Also used : Project(com.intellij.openapi.project.Project) TemplateManagerImpl(com.intellij.codeInsight.template.impl.TemplateManagerImpl) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor) TemplateState(com.intellij.codeInsight.template.impl.TemplateState) EditorWindow(com.intellij.injected.editor.EditorWindow) TestOnly(org.jetbrains.annotations.TestOnly)

Example 9 with EditorWindow

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

the class CodeInsightTestFixtureImpl method getElementAtCaret.

@Override
@NotNull
public PsiElement getElementAtCaret() {
    assertInitialized();
    Editor editor = getCompletionEditor();
    int findTargetFlags = TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtil.ELEMENT_NAME_ACCEPTED;
    PsiElement element = TargetElementUtil.findTargetElement(editor, findTargetFlags);
    // if no references found in injected fragment, try outer document
    if (element == null && editor instanceof EditorWindow) {
        element = TargetElementUtil.findTargetElement(((EditorWindow) editor).getDelegate(), findTargetFlags);
    }
    if (element == null) {
        fail("element not found in file " + myFile.getName() + " at caret position offset " + myEditor.getCaretModel().getOffset() + "," + " psi structure:\n" + DebugUtil.psiToString(getFile(), true, true));
    }
    return element;
}
Also used : com.intellij.openapi.fileEditor(com.intellij.openapi.fileEditor) ExtensionPoint(com.intellij.openapi.extensions.ExtensionPoint) EditorWindow(com.intellij.injected.editor.EditorWindow) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with EditorWindow

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

the class CodeInsightTestFixtureImpl method doHighlighting.

@Override
@NotNull
public List<HighlightInfo> doHighlighting() {
    final Project project = getProject();
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    PsiFile file = getFile();
    Editor editor = getEditor();
    if (editor instanceof EditorWindow) {
        editor = ((EditorWindow) editor).getDelegate();
        file = InjectedLanguageUtil.getTopLevelFile(file);
    }
    assertNotNull(file);
    return instantiateAndRun(file, editor, ArrayUtil.EMPTY_INT_ARRAY, myAllowDirt);
}
Also used : Project(com.intellij.openapi.project.Project) com.intellij.openapi.fileEditor(com.intellij.openapi.fileEditor) EditorWindow(com.intellij.injected.editor.EditorWindow) NotNull(org.jetbrains.annotations.NotNull)

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