Search in sources :

Example 36 with EditorEx

use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.

the class MergePanel2 method setHighlighterSettings.

private void setHighlighterSettings(@Nullable EditorColorsScheme settings, @NotNull EditorPlace place) {
    if (settings == null) {
        settings = EditorColorsManager.getInstance().getGlobalScheme();
    }
    Editor editor = place.getEditor();
    DiffEditorState editorState = place.getState();
    if (editor != null) {
        ((EditorEx) editor).setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(editorState.getFileType(), settings, editorState.getProject()));
    }
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) Editor(com.intellij.openapi.editor.Editor)

Example 37 with EditorEx

use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.

the class TextEditorImpl method loadEditorInBackground.

@NotNull
protected Runnable loadEditorInBackground() {
    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(myFile, scheme, myProject);
    EditorEx editor = (EditorEx) getEditor();
    highlighter.setText(editor.getDocument().getImmutableCharSequence());
    return () -> editor.setHighlighter(highlighter);
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter) BackgroundEditorHighlighter(com.intellij.codeHighlighting.BackgroundEditorHighlighter) NotNull(org.jetbrains.annotations.NotNull)

Example 38 with EditorEx

use of com.intellij.openapi.editor.ex.EditorEx in project intellij-plugins by JetBrains.

the class CfmlTypedHandler method beforeCharTyped.

public Result beforeCharTyped(final char c, final Project project, final Editor editor, final PsiFile file, final FileType fileType) {
    PsiFile cfmlFile = file.getViewProvider().getPsi(CfmlLanguage.INSTANCE);
    if (isNotCfmlFile(cfmlFile, editor)) {
        return Result.CONTINUE;
    }
    int offset = editor.getCaretModel().getOffset();
    if (c == '{') {
        CfmlBraceMatcher braceMatcher = new CfmlBraceMatcher();
        HighlighterIterator iterator = ((EditorEx) editor).getHighlighter().createIterator(offset);
        if (!braceMatcher.isLBraceToken(iterator, editor.getDocument().getCharsSequence(), fileType)) {
            EditorModificationUtil.insertStringAtCaret(editor, "}", true, 0);
        // return Result.STOP;
        }
        return Result.CONTINUE;
    }
    if (c == '#') {
        if (ourEnableDoublePoundInsertion && CfmlEditorUtil.countSharpsBalance(editor) == 0) {
            char charAtOffset = DocumentUtils.getCharAt(editor.getDocument(), offset);
            if (charAtOffset == '#') {
                EditorModificationUtil.moveCaretRelatively(editor, 1);
                return Result.STOP;
            }
            EditorModificationUtil.insertStringAtCaret(editor, "#", true, 0);
        }
    } else if (c == '>') {
        if (((EditorEx) editor).getHighlighter().createIterator(editor.getCaretModel().getOffset()).getTokenType() == CfmlTokenTypes.COMMENT || ((EditorEx) editor).getHighlighter().createIterator(editor.getCaretModel().getOffset()).getTokenType().getLanguage() != CfmlLanguage.INSTANCE) {
            return Result.CONTINUE;
        }
        insertCloseTagIfNeeded(editor, cfmlFile, project);
        return Result.STOP;
    }
    return Result.CONTINUE;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) PsiFile(com.intellij.psi.PsiFile) CfmlBraceMatcher(com.intellij.coldFusion.UI.editorActions.matchers.CfmlBraceMatcher) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator)

Example 39 with EditorEx

use of com.intellij.openapi.editor.ex.EditorEx in project intellij-plugins by JetBrains.

the class CfmlTypedHandlerTest method testEditing.

public void testEditing() throws Throwable {
    @NonNls final String s1 = "<table bgcolor=\"#FFFFFF\"><cfoutput>\n" + "  <div id=\"#bColumn2";
    String s2 = "\" />\n" + "</cfoutput></table>";
    String s = s1 + s2;
    final Document doc = new DocumentImpl(s);
    EditorEx editor = (EditorEx) EditorFactory.getInstance().createEditor(doc);
    try {
        EditorHighlighter highlighter = HighlighterFactory.createHighlighter(getProject(), CfmlFileType.INSTANCE);
        editor.setHighlighter(highlighter);
        CommandProcessor.getInstance().executeCommand(getProject(), () -> ApplicationManager.getApplication().runWriteAction(() -> doc.insertString(s1.length(), "#")), "", null);
        List tokensAfterUpdate = getAllTokens(highlighter);
        highlighter = HighlighterFactory.createHighlighter(getProject(), CfmlFileType.INSTANCE);
        editor.setHighlighter(highlighter);
        List tokensWithoutUpdate = getAllTokens(highlighter);
        TestCase.assertEquals(tokensWithoutUpdate, tokensAfterUpdate);
    } finally {
        EditorFactory.getInstance().releaseEditor(editor);
    }
}
Also used : NonNls(org.jetbrains.annotations.NonNls) EditorEx(com.intellij.openapi.editor.ex.EditorEx) List(java.util.List) Document(com.intellij.openapi.editor.Document) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 40 with EditorEx

use of com.intellij.openapi.editor.ex.EditorEx in project android by JetBrains.

the class AndroidFindUsagesTest method findUsages.

private static Collection<UsageInfo> findUsages(String fileName, final JavaCodeInsightTestFixture fixture, String newFilePath) throws Throwable {
    VirtualFile file = fixture.copyFileToProject(BASE_PATH + fileName, newFilePath);
    fixture.configureFromExistingVirtualFile(file);
    final UsageTarget[] targets = UsageTargetUtil.findUsageTargets(new DataProvider() {

        @Override
        public Object getData(@NonNls String dataId) {
            return ((EditorEx) fixture.getEditor()).getDataContext().getData(dataId);
        }
    });
    assert targets != null && targets.length > 0 && targets[0] instanceof PsiElementUsageTarget;
    return fixture.findUsages(((PsiElementUsageTarget) targets[0]).getElement());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DataProvider(com.intellij.openapi.actionSystem.DataProvider) EditorEx(com.intellij.openapi.editor.ex.EditorEx) PsiElementUsageTarget(com.intellij.usages.PsiElementUsageTarget) UsageTarget(com.intellij.usages.UsageTarget) PsiElementUsageTarget(com.intellij.usages.PsiElementUsageTarget)

Aggregations

EditorEx (com.intellij.openapi.editor.ex.EditorEx)164 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)36 Editor (com.intellij.openapi.editor.Editor)35 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)33 Document (com.intellij.openapi.editor.Document)29 NotNull (org.jetbrains.annotations.NotNull)26 IElementType (com.intellij.psi.tree.IElementType)14 Nullable (org.jetbrains.annotations.Nullable)13 Project (com.intellij.openapi.project.Project)12 PsiFile (com.intellij.psi.PsiFile)12 EditorFactory (com.intellij.openapi.editor.EditorFactory)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 TextRange (com.intellij.openapi.util.TextRange)10 FileType (com.intellij.openapi.fileTypes.FileType)8 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)7 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)7 BraceMatcher (com.intellij.codeInsight.highlighting.BraceMatcher)6 Language (com.intellij.lang.Language)6 CaretModel (com.intellij.openapi.editor.CaretModel)6 EditorGutterComponentEx (com.intellij.openapi.editor.ex.EditorGutterComponentEx)6