Search in sources :

Example 36 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class IndentsPass method doApplyInformationToEditor.

@Override
public void doApplyInformationToEditor() {
    final Long stamp = myEditor.getUserData(LAST_TIME_INDENTS_BUILT);
    if (stamp != null && stamp.longValue() == nowStamp())
        return;
    List<RangeHighlighter> oldHighlighters = myEditor.getUserData(INDENT_HIGHLIGHTERS_IN_EDITOR_KEY);
    final List<RangeHighlighter> newHighlighters = new ArrayList<>();
    final MarkupModel mm = myEditor.getMarkupModel();
    int curRange = 0;
    if (oldHighlighters != null) {
        int curHighlight = 0;
        while (curRange < myRanges.size() && curHighlight < oldHighlighters.size()) {
            TextRange range = myRanges.get(curRange);
            RangeHighlighter highlighter = oldHighlighters.get(curHighlight);
            int cmp = compare(range, highlighter);
            if (cmp < 0) {
                newHighlighters.add(createHighlighter(mm, range));
                curRange++;
            } else if (cmp > 0) {
                highlighter.dispose();
                curHighlight++;
            } else {
                newHighlighters.add(highlighter);
                curHighlight++;
                curRange++;
            }
        }
        for (; curHighlight < oldHighlighters.size(); curHighlight++) {
            RangeHighlighter highlighter = oldHighlighters.get(curHighlight);
            highlighter.dispose();
        }
    }
    final int startRangeIndex = curRange;
    assert myDocument != null;
    DocumentUtil.executeInBulk(myDocument, myRanges.size() > 10000, () -> {
        for (int i = startRangeIndex; i < myRanges.size(); i++) {
            newHighlighters.add(createHighlighter(mm, myRanges.get(i)));
        }
    });
    myEditor.putUserData(INDENT_HIGHLIGHTERS_IN_EDITOR_KEY, newHighlighters);
    myEditor.putUserData(LAST_TIME_INDENTS_BUILT, nowStamp());
    myEditor.getIndentsModel().assumeIndents(myDescriptors);
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TextRange(com.intellij.openapi.util.TextRange) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel)

Example 37 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class LineMarkersUtil method createOrReuseLineMarker.

@NotNull
private static RangeHighlighter createOrReuseLineMarker(@NotNull LineMarkerInfo info, @NotNull MarkupModel markupModel, @Nullable HighlightersRecycler toReuse) {
    RangeHighlighter highlighter = toReuse == null ? null : toReuse.pickupHighlighterFromGarbageBin(info.startOffset, info.endOffset, HighlighterLayer.ADDITIONAL_SYNTAX);
    if (highlighter == null) {
        highlighter = markupModel.addRangeHighlighter(info.startOffset, info.endOffset, HighlighterLayer.ADDITIONAL_SYNTAX, null, HighlighterTargetArea.LINES_IN_RANGE);
    }
    highlighter.putUserData(LINE_MARKER_INFO, info);
    LineMarkerInfo.LineMarkerGutterIconRenderer newRenderer = (LineMarkerInfo.LineMarkerGutterIconRenderer) info.createGutterRenderer();
    LineMarkerInfo.LineMarkerGutterIconRenderer oldRenderer = highlighter.getGutterIconRenderer() instanceof LineMarkerInfo.LineMarkerGutterIconRenderer ? (LineMarkerInfo.LineMarkerGutterIconRenderer) highlighter.getGutterIconRenderer() : null;
    boolean rendererChanged = oldRenderer == null || newRenderer == null || !newRenderer.equals(oldRenderer);
    boolean lineSeparatorColorChanged = !Comparing.equal(highlighter.getLineSeparatorColor(), info.separatorColor);
    boolean lineSeparatorPlacementChanged = !Comparing.equal(highlighter.getLineSeparatorPlacement(), info.separatorPlacement);
    if (rendererChanged || lineSeparatorColorChanged || lineSeparatorPlacementChanged) {
        ((MarkupModelEx) markupModel).changeAttributesInBatch((RangeHighlighterEx) highlighter, markerEx -> {
            if (rendererChanged) {
                markerEx.setGutterIconRenderer(newRenderer);
            }
            if (lineSeparatorColorChanged) {
                markerEx.setLineSeparatorColor(info.separatorColor);
            }
            if (lineSeparatorPlacementChanged) {
                markerEx.setLineSeparatorPlacement(info.separatorPlacement);
            }
        });
    }
    info.highlighter = highlighter;
    return highlighter;
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) NotNull(org.jetbrains.annotations.NotNull)

Example 38 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter 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 39 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class HighlightUsagesHandler method highlightRanges.

public static void highlightRanges(HighlightManager highlightManager, Editor editor, TextAttributes attributes, boolean clearHighlights, List<TextRange> textRanges) {
    if (clearHighlights) {
        clearHighlights(editor, highlightManager, textRanges, attributes);
        return;
    }
    ArrayList<RangeHighlighter> highlighters = new ArrayList<>();
    for (TextRange range : textRanges) {
        highlightManager.addRangeHighlight(editor, range.getStartOffset(), range.getEndOffset(), attributes, false, highlighters);
    }
    for (RangeHighlighter highlighter : highlighters) {
        String tooltip = getLineTextErrorStripeTooltip(editor.getDocument(), highlighter.getStartOffset(), true);
        highlighter.setErrorStripeTooltip(tooltip);
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) ArrayList(java.util.ArrayList) TextRange(com.intellij.openapi.util.TextRange)

Example 40 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class InplaceRefactoring method addHighlights.

protected void addHighlights(@NotNull Map<TextRange, TextAttributes> ranges, @NotNull Editor editor, @NotNull Collection<RangeHighlighter> highlighters, @NotNull HighlightManager highlightManager) {
    for (Map.Entry<TextRange, TextAttributes> entry : ranges.entrySet()) {
        TextRange range = entry.getKey();
        TextAttributes attributes = entry.getValue();
        highlightManager.addOccurrenceHighlight(editor, range.getStartOffset(), range.getEndOffset(), attributes, 0, highlighters, null);
    }
    for (RangeHighlighter highlighter : highlighters) {
        highlighter.setGreedyToLeft(true);
        highlighter.setGreedyToRight(true);
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes)

Aggregations

RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)102 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)29 TextRange (com.intellij.openapi.util.TextRange)23 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)18 Editor (com.intellij.openapi.editor.Editor)17 ArrayList (java.util.ArrayList)16 NotNull (org.jetbrains.annotations.NotNull)15 Project (com.intellij.openapi.project.Project)13 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)10 MarkupModel (com.intellij.openapi.editor.markup.MarkupModel)10 Document (com.intellij.openapi.editor.Document)9 RelativePoint (com.intellij.ui.awt.RelativePoint)8 Nullable (org.jetbrains.annotations.Nullable)8 EditorEx (com.intellij.openapi.editor.ex.EditorEx)7 MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)7 PsiElement (com.intellij.psi.PsiElement)6 EditorWindow (com.intellij.injected.editor.EditorWindow)4 Result (com.intellij.openapi.application.Result)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)4 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)4