Search in sources :

Example 11 with EditorHighlighter

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

the class DiffSideView method applyHighlighter.

private void applyHighlighter() {
    EditorEx editor = myEditorSource.getEditor();
    if (editor == null)
        return;
    EditorHighlighter highlighter = myHighlighterFactory.createHighlighter();
    if (highlighter != null)
        editor.setHighlighter(highlighter);
    editor.getSettings().setCaretRowShown(false);
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 12 with EditorHighlighter

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

the class EditorHighlighterCache method getLexerBasedOnLexerHighlighter.

@Nullable
public static Lexer getLexerBasedOnLexerHighlighter(CharSequence text, VirtualFile virtualFile, Project project) {
    EditorHighlighter highlighter = null;
    PsiFile psiFile = virtualFile != null ? PsiManager.getInstance(project).findFile(virtualFile) : null;
    final Document document = psiFile != null ? PsiDocumentManager.getInstance(project).getDocument(psiFile) : null;
    final EditorHighlighter cachedEditorHighlighter;
    boolean alreadyInitializedHighlighter = false;
    if (document != null && (cachedEditorHighlighter = getEditorHighlighterForCachesBuilding(document)) != null && PlatformIdTableBuilding.checkCanUseCachedEditorHighlighter(text, cachedEditorHighlighter)) {
        highlighter = cachedEditorHighlighter;
        alreadyInitializedHighlighter = true;
    } else if (virtualFile != null) {
        highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(project, virtualFile);
    }
    if (highlighter != null) {
        return new LexerEditorHighlighterLexer(highlighter, alreadyInitializedHighlighter);
    }
    return null;
}
Also used : LexerEditorHighlighterLexer(com.intellij.psi.impl.search.LexerEditorHighlighterLexer) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with EditorHighlighter

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

the class EditorHighlighterCache method getEditorHighlighterForCachesBuilding.

@Nullable
public static EditorHighlighter getEditorHighlighterForCachesBuilding(Document document) {
    if (document == null) {
        return null;
    }
    final WeakReference<EditorHighlighter> editorHighlighterWeakReference = document.getUserData(ourSomeEditorSyntaxHighlighter);
    final EditorHighlighter someEditorHighlighter = SoftReference.dereference(editorHighlighterWeakReference);
    if (someEditorHighlighter instanceof LexerEditorHighlighter && ((LexerEditorHighlighter) someEditorHighlighter).isValid()) {
        return someEditorHighlighter;
    }
    document.putUserData(ourSomeEditorSyntaxHighlighter, null);
    return null;
}
Also used : LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with EditorHighlighter

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

the class UnifiedDiffViewer method performRediff.

@Override
@NotNull
protected Runnable performRediff(@NotNull final ProgressIndicator indicator) {
    try {
        indicator.checkCanceled();
        final Document document1 = getContent1().getDocument();
        final Document document2 = getContent2().getDocument();
        final CharSequence[] texts = ReadAction.compute(() -> {
            return new CharSequence[] { document1.getImmutableCharSequence(), document2.getImmutableCharSequence() };
        });
        final List<LineFragment> fragments = myTextDiffProvider.compare(texts[0], texts[1], indicator);
        final DocumentContent content1 = getContent1();
        final DocumentContent content2 = getContent2();
        indicator.checkCanceled();
        TwosideDocumentData data = ReadAction.compute(() -> {
            indicator.checkCanceled();
            UnifiedFragmentBuilder builder = new UnifiedFragmentBuilder(fragments, document1, document2, myMasterSide);
            builder.exec();
            indicator.checkCanceled();
            EditorHighlighter highlighter = buildHighlighter(myProject, content1, content2, texts[0], texts[1], builder.getRanges(), builder.getText().length());
            UnifiedEditorRangeHighlighter rangeHighlighter = new UnifiedEditorRangeHighlighter(myProject, document1, document2, builder.getRanges());
            return new TwosideDocumentData(builder, highlighter, rangeHighlighter);
        });
        UnifiedFragmentBuilder builder = data.getBuilder();
        FileType fileType = content2.getContentType() == null ? content1.getContentType() : content2.getContentType();
        LineNumberConvertor convertor1 = builder.getConvertor1();
        LineNumberConvertor convertor2 = builder.getConvertor2();
        List<LineRange> changedLines = builder.getChangedLines();
        boolean isContentsEqual = builder.isEqual();
        CombinedEditorData editorData = new CombinedEditorData(builder.getText(), data.getHighlighter(), data.getRangeHighlighter(), fileType, convertor1.createConvertor(), convertor2.createConvertor());
        return apply(editorData, builder.getBlocks(), convertor1, convertor2, changedLines, isContentsEqual);
    } catch (DiffTooBigException e) {
        return () -> {
            clearDiffPresentation();
            myPanel.setTooBigContent();
        };
    } catch (ProcessCanceledException e) {
        throw e;
    } catch (Throwable e) {
        LOG.error(e);
        return () -> {
            clearDiffPresentation();
            myPanel.setErrorContent();
        };
    }
}
Also used : LineFragment(com.intellij.diff.fragments.LineFragment) FileType(com.intellij.openapi.fileTypes.FileType) DocumentContent(com.intellij.diff.contents.DocumentContent) DiffTooBigException(com.intellij.diff.comparison.DiffTooBigException) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 15 with EditorHighlighter

use of com.intellij.openapi.editor.highlighter.EditorHighlighter 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)

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