use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class LivePreview method clearUnusedHightlighters.
private void clearUnusedHightlighters() {
Set<RangeHighlighter> unused = new com.intellij.util.containers.HashSet<>();
for (RangeHighlighter highlighter : myHighlighters) {
if (highlighter.getUserData(MARKER_USED) == null) {
unused.add(highlighter);
} else {
highlighter.putUserData(MARKER_USED, null);
}
}
myHighlighters.removeAll(unused);
Project project = mySearchResults.getProject();
if (project != null && !project.isDisposed()) {
for (RangeHighlighter highlighter : unused) {
HighlightManager.getInstance(project).removeSegmentHighlighter(mySearchResults.getEditor(), highlighter);
}
}
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class LivePreview method dumpEditorMarkupAndSelection.
private void dumpEditorMarkupAndSelection(PrintStream dumpStream) {
dumpStream.println(mySearchResults.getFindModel());
if (myReplacementPreviewText != null) {
dumpStream.println("--");
dumpStream.println("Replacement Preview: " + myReplacementPreviewText);
}
dumpStream.println("--");
Editor editor = mySearchResults.getEditor();
RangeHighlighter[] highlighters = editor.getMarkupModel().getAllHighlighters();
List<Pair<Integer, Character>> ranges = new ArrayList<>();
for (RangeHighlighter highlighter : highlighters) {
ranges.add(new Pair<>(highlighter.getStartOffset(), '['));
ranges.add(new Pair<>(highlighter.getEndOffset(), ']'));
}
SelectionModel selectionModel = editor.getSelectionModel();
if (selectionModel.getSelectionStart() != selectionModel.getSelectionEnd()) {
ranges.add(new Pair<>(selectionModel.getSelectionStart(), '<'));
ranges.add(new Pair<>(selectionModel.getSelectionEnd(), '>'));
}
ranges.add(new Pair<>(-1, '\n'));
ranges.add(new Pair<>(editor.getDocument().getTextLength() + 1, '\n'));
ContainerUtil.sort(ranges, (pair, pair2) -> {
int res = pair.first - pair2.first;
if (res == 0) {
Character c1 = pair.second;
Character c2 = pair2.second;
if (c1 == '<' && c2 == '[') {
return 1;
} else if (c1 == '[' && c2 == '<') {
return -1;
}
return c1.compareTo(c2);
}
return res;
});
Document document = editor.getDocument();
for (int i = 0; i < ranges.size() - 1; ++i) {
Pair<Integer, Character> pair = ranges.get(i);
Pair<Integer, Character> pair1 = ranges.get(i + 1);
dumpStream.print(pair.second + document.getText(TextRange.create(Math.max(pair.first, 0), Math.min(pair1.first, document.getTextLength()))));
}
dumpStream.println("\n--");
if (NotFound) {
dumpStream.println("Not Found");
dumpStream.println("--");
NotFound = false;
}
for (RangeHighlighter highlighter : highlighters) {
dumpStream.println(highlighter + " : " + highlighter.getTextAttributes());
}
dumpStream.println("------------");
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class LivePreview method updateInSelectionHighlighters.
private void updateInSelectionHighlighters() {
if (mySearchResults.getEditor() == null)
return;
final SelectionModel selectionModel = mySearchResults.getEditor().getSelectionModel();
int[] starts = selectionModel.getBlockSelectionStarts();
int[] ends = selectionModel.getBlockSelectionEnds();
final HashSet<RangeHighlighter> toRemove = new HashSet<>();
Set<RangeHighlighter> toAdd = new HashSet<>();
for (RangeHighlighter highlighter : myHighlighters) {
if (!highlighter.isValid())
continue;
boolean intersectsWithSelection = false;
for (int i = 0; i < starts.length; ++i) {
TextRange selectionRange = new TextRange(starts[i], ends[i]);
intersectsWithSelection = selectionRange.intersects(highlighter.getStartOffset(), highlighter.getEndOffset()) && selectionRange.getEndOffset() != highlighter.getStartOffset() && highlighter.getEndOffset() != selectionRange.getStartOffset();
if (intersectsWithSelection)
break;
}
final Object userData = highlighter.getUserData(IN_SELECTION_KEY);
if (userData != null) {
if (!intersectsWithSelection) {
if (userData == IN_SELECTION2) {
HighlightManager.getInstance(mySearchResults.getProject()).removeSegmentHighlighter(mySearchResults.getEditor(), highlighter);
toRemove.add(highlighter);
} else {
highlighter.putUserData(IN_SELECTION_KEY, null);
}
}
} else if (intersectsWithSelection) {
TextRange cursor = mySearchResults.getCursor();
if (cursor != null && highlighter.getStartOffset() == cursor.getStartOffset() && highlighter.getEndOffset() == cursor.getEndOffset())
continue;
final RangeHighlighter toAnnotate = highlightRange(new TextRange(highlighter.getStartOffset(), highlighter.getEndOffset()), new TextAttributes(null, null, Color.WHITE, EffectType.ROUNDED_BOX, Font.PLAIN), toAdd);
highlighter.putUserData(IN_SELECTION_KEY, IN_SELECTION1);
toAnnotate.putUserData(IN_SELECTION_KEY, IN_SELECTION2);
}
}
myHighlighters.removeAll(toRemove);
myHighlighters.addAll(toAdd);
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class HighlightUsagesHandler method clearHighlights.
private static void clearHighlights(Editor editor, HighlightManager highlightManager, List<TextRange> rangesToHighlight, TextAttributes attributes) {
if (editor instanceof EditorWindow)
editor = ((EditorWindow) editor).getDelegate();
RangeHighlighter[] highlighters = ((HighlightManagerImpl) highlightManager).getHighlighters(editor);
Arrays.sort(highlighters, (o1, o2) -> o1.getStartOffset() - o2.getStartOffset());
Collections.sort(rangesToHighlight, (o1, o2) -> o1.getStartOffset() - o2.getStartOffset());
int i = 0;
int j = 0;
while (i < highlighters.length && j < rangesToHighlight.size()) {
RangeHighlighter highlighter = highlighters[i];
TextRange highlighterRange = TextRange.create(highlighter);
TextRange refRange = rangesToHighlight.get(j);
if (refRange.equals(highlighterRange) && attributes.equals(highlighter.getTextAttributes()) && highlighter.getLayer() == HighlighterLayer.SELECTION - 1) {
highlightManager.removeSegmentHighlighter(editor, highlighter);
i++;
} else if (refRange.getStartOffset() > highlighterRange.getEndOffset()) {
i++;
} else if (refRange.getEndOffset() < highlighterRange.getStartOffset()) {
j++;
} else {
i++;
j++;
}
}
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class BreadcrumbsXmlWrapper method itemHovered.
@Override
public void itemHovered(@Nullable BreadcrumbsPsiItem item) {
if (!Registry.is("editor.breadcrumbs.highlight.on.hover")) {
return;
}
HighlightManager hm = HighlightManager.getInstance(myProject);
if (myHighlighed != null) {
for (RangeHighlighter highlighter : myHighlighed) {
hm.removeSegmentHighlighter(myEditor, highlighter);
}
myHighlighed = null;
}
if (item != null) {
final TextRange range = item.getPsiElement().getTextRange();
final TextAttributes attributes = new TextAttributes();
final CrumbPresentation p = item.getPresentation();
final Color color = p != null ? p.getBackgroundColor(false, false, false) : BreadcrumbsComponent.ButtonSettings.getBackgroundColor(false, false, false, false);
final Color background = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.CARET_ROW_COLOR);
attributes.setBackgroundColor(XmlTagTreeHighlightingUtil.makeTransparent(color, background != null ? background : Gray._200, 0.3));
myHighlighed = new ArrayList<>(1);
int flags = HighlightManager.HIDE_BY_ESCAPE | HighlightManager.HIDE_BY_TEXT_CHANGE | HighlightManager.HIDE_BY_ANY_KEY;
hm.addOccurrenceHighlight(myEditor, range.getStartOffset(), range.getEndOffset(), attributes, flags, myHighlighed, null);
}
}
Aggregations