Search in sources :

Example 41 with EditorHighlighter

use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-community by JetBrains.

the class EditorActionUtil method isLexemeBoundary.

/**
   * Finds out whether there's a boundary between two lexemes of different type at given offset.
   */
public static boolean isLexemeBoundary(@NotNull Editor editor, int offset) {
    if (!(editor instanceof EditorEx) || offset <= 0 || offset >= editor.getDocument().getTextLength() || DocumentUtil.isInsideSurrogatePair(editor.getDocument(), offset)) {
        return false;
    }
    if (CharArrayUtil.isEmptyOrSpaces(editor.getDocument().getImmutableCharSequence(), offset - 1, offset + 1))
        return false;
    EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
    HighlighterIterator it = highlighter.createIterator(offset);
    if (it.getStart() != offset) {
        return false;
    }
    IElementType rightToken = it.getTokenType();
    it.retreat();
    IElementType leftToken = it.getTokenType();
    return !Comparing.equal(leftToken, rightToken);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) EditorEx(com.intellij.openapi.editor.ex.EditorEx) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 42 with EditorHighlighter

use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-community by JetBrains.

the class MergePanel2 method setupHighlighterSettings.

private void setupHighlighterSettings(Editor left, Editor base, Editor right) {
    Editor[] editors = new Editor[] { left, base, right };
    DiffContent[] contents = myData.getContents();
    FileType[] types = DiffUtil.chooseContentTypes(contents);
    VirtualFile fallbackFile = contents[1].getFile();
    FileType fallbackType = contents[1].getContentType();
    for (int i = 0; i < 3; i++) {
        Editor editor = editors[i];
        DiffContent content = contents[i];
        EditorHighlighter highlighter = createHighlighter(types[i], content.getFile(), fallbackFile, fallbackType, myData.getProject()).createHighlighter();
        if (highlighter != null) {
            ((EditorEx) editor).setHighlighter(highlighter);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) EditorEx(com.intellij.openapi.editor.ex.EditorEx) FileType(com.intellij.openapi.fileTypes.FileType) Editor(com.intellij.openapi.editor.Editor) DiffDividerPaint(com.intellij.openapi.diff.impl.splitter.DiffDividerPaint) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 43 with EditorHighlighter

use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-community by JetBrains.

the class UnifiedDiffViewer method buildHighlighter.

@Nullable
private EditorHighlighter buildHighlighter(@Nullable Project project, @NotNull DocumentContent content1, @NotNull DocumentContent content2, @NotNull CharSequence text1, @NotNull CharSequence text2, @NotNull List<HighlightRange> ranges, int textLength) {
    EditorHighlighter highlighter1 = DiffUtil.initEditorHighlighter(project, content1, text1);
    EditorHighlighter highlighter2 = DiffUtil.initEditorHighlighter(project, content2, text2);
    if (highlighter1 == null && highlighter2 == null)
        return null;
    if (highlighter1 == null)
        highlighter1 = DiffUtil.initEmptyEditorHighlighter(text1);
    if (highlighter2 == null)
        highlighter2 = DiffUtil.initEmptyEditorHighlighter(text2);
    return new UnifiedEditorHighlighter(myDocument, highlighter1, highlighter2, ranges, textLength);
}
Also used : EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 44 with EditorHighlighter

use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-community by JetBrains.

the class DiffUtil method initEditorHighlighter.

@Nullable
public static EditorHighlighter initEditorHighlighter(@Nullable Project project, @NotNull DocumentContent content, @NotNull CharSequence text) {
    EditorHighlighter highlighter = createEditorHighlighter(project, content);
    if (highlighter == null)
        return null;
    highlighter.setText(text);
    return highlighter;
}
Also used : EmptyEditorHighlighter(com.intellij.openapi.editor.ex.util.EmptyEditorHighlighter) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 45 with EditorHighlighter

use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-community by JetBrains.

the class PrintManager method doInitTextPainter.

private static TextPainter doInitTextPainter(@NotNull final DocumentEx doc, Project project) {
    EditorHighlighter highlighter = HighlighterFactory.createHighlighter(project, "unknown");
    highlighter.setText(doc.getCharsSequence());
    return new TextPainter(doc, highlighter, "unknown", "unknown", project, FileTypes.PLAIN_TEXT, null);
}
Also used : EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Aggregations

EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)63 EditorEx (com.intellij.openapi.editor.ex.EditorEx)36 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)36 Document (com.intellij.openapi.editor.Document)13 IElementType (com.intellij.psi.tree.IElementType)11 Editor (com.intellij.openapi.editor.Editor)8 FileType (com.intellij.openapi.fileTypes.FileType)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 NotNull (org.jetbrains.annotations.NotNull)8 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)7 PsiFile (com.intellij.psi.PsiFile)7 LexerEditorHighlighter (com.intellij.openapi.editor.ex.util.LexerEditorHighlighter)6 SyntaxHighlighter (com.intellij.openapi.fileTypes.SyntaxHighlighter)5 PsiElement (com.intellij.psi.PsiElement)5 Language (com.intellij.lang.Language)4 CaretModel (com.intellij.openapi.editor.CaretModel)4 Project (com.intellij.openapi.project.Project)4 BraceMatcher (com.intellij.codeInsight.highlighting.BraceMatcher)3 EditorWindow (com.intellij.injected.editor.EditorWindow)3 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)3