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);
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations