use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class CtrlMouseHandler method installHighlighterSet.
@NotNull
private HighlightersSet installHighlighterSet(@NotNull Info info, @NotNull Editor editor) {
final JComponent internalComponent = editor.getContentComponent();
internalComponent.addKeyListener(myEditorKeyListener);
editor.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener);
final Cursor cursor = internalComponent.getCursor();
if (info.isNavigatable()) {
internalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
myFileEditorManager.addFileEditorManagerListener(myFileEditorManagerListener);
List<RangeHighlighter> highlighters = new ArrayList<>();
TextAttributes attributes = info.isNavigatable() ? myEditorColorsManager.getGlobalScheme().getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR) : new TextAttributes(null, HintUtil.getInformationColor(), null, null, Font.PLAIN);
for (TextRange range : info.getRanges()) {
TextAttributes attr = NavigationUtil.patchAttributesColor(attributes, range, editor);
final RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), HighlighterLayer.HYPERLINK, attr, HighlighterTargetArea.EXACT_RANGE);
highlighters.add(highlighter);
}
return new HighlightersSet(highlighters, editor, cursor, info);
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class FindManagerImpl method findNextUsageInFile.
private boolean findNextUsageInFile(@NotNull FileEditor fileEditor, @NotNull SearchResults.Direction direction) {
if (fileEditor instanceof TextEditor) {
TextEditor textEditor = (TextEditor) fileEditor;
Editor editor = textEditor.getEditor();
editor.getCaretModel().removeSecondaryCarets();
if (tryToFindNextUsageViaEditorSearchComponent(editor, direction)) {
return true;
}
RangeHighlighter[] highlighters = ((HighlightManagerImpl) HighlightManager.getInstance(myProject)).getHighlighters(editor);
if (highlighters.length > 0) {
return highlightNextHighlighter(highlighters, editor, editor.getCaretModel().getOffset(), direction == SearchResults.Direction.DOWN, false);
}
}
if (direction == SearchResults.Direction.DOWN) {
return myFindUsagesManager.findNextUsageInFile(fileEditor);
}
return myFindUsagesManager.findPreviousUsageInFile(fileEditor);
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class LivePreview method doHightlightRange.
private RangeHighlighter doHightlightRange(final TextRange textRange, final TextAttributes attributes, Set<RangeHighlighter> highlighters) {
HighlightManager highlightManager = HighlightManager.getInstance(mySearchResults.getProject());
MarkupModelEx markupModel = (MarkupModelEx) mySearchResults.getEditor().getMarkupModel();
final RangeHighlighter[] candidate = new RangeHighlighter[1];
boolean notFound = markupModel.processRangeHighlightersOverlappingWith(textRange.getStartOffset(), textRange.getEndOffset(), highlighter -> {
TextAttributes textAttributes = highlighter.getTextAttributes();
if (highlighter.getUserData(SEARCH_MARKER) != null && textAttributes != null && textAttributes.equals(attributes) && highlighter.getStartOffset() == textRange.getStartOffset() && highlighter.getEndOffset() == textRange.getEndOffset()) {
candidate[0] = highlighter;
return false;
}
return true;
});
if (!notFound && highlighters.contains(candidate[0])) {
return candidate[0];
}
final ArrayList<RangeHighlighter> dummy = new ArrayList<>();
highlightManager.addRangeHighlight(mySearchResults.getEditor(), textRange.getStartOffset(), textRange.getEndOffset(), attributes, false, dummy);
final RangeHighlighter h = dummy.get(0);
highlighters.add(h);
h.putUserData(SEARCH_MARKER, YES);
return h;
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class LivePreview method removeFromEditor.
private void removeFromEditor() {
Editor editor = mySearchResults.getEditor();
if (myReplacementBalloon != null) {
myReplacementBalloon.hide();
}
if (editor != null) {
for (VisibleAreaListener visibleAreaListener : myVisibleAreaListenersToRemove) {
editor.getScrollingModel().removeVisibleAreaListener(visibleAreaListener);
}
myVisibleAreaListenersToRemove.clear();
Project project = mySearchResults.getProject();
if (project != null && !project.isDisposed()) {
for (RangeHighlighter h : myHighlighters) {
HighlightManager.getInstance(project).removeSegmentHighlighter(editor, h);
}
if (myCursorHighlighter != null) {
HighlightManager.getInstance(project).removeSegmentHighlighter(editor, myCursorHighlighter);
myCursorHighlighter = null;
}
}
myHighlighters.clear();
if (myListeningSelection) {
editor.getSelectionModel().removeSelectionListener(this);
myListeningSelection = false;
}
}
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class LivePreview method updateCursorHighlighting.
private void updateCursorHighlighting() {
hideBalloon();
if (myCursorHighlighter != null) {
HighlightManager.getInstance(mySearchResults.getProject()).removeSegmentHighlighter(mySearchResults.getEditor(), myCursorHighlighter);
myCursorHighlighter = null;
}
final FindResult cursor = mySearchResults.getCursor();
Editor editor = mySearchResults.getEditor();
if (cursor != null && cursor.getEndOffset() <= editor.getDocument().getTextLength()) {
Set<RangeHighlighter> dummy = new HashSet<>();
Color color = editor.getColorsScheme().getColor(EditorColors.CARET_COLOR);
highlightRange(cursor, new TextAttributes(null, null, color, EffectType.ROUNDED_BOX, Font.PLAIN), dummy);
if (!dummy.isEmpty()) {
myCursorHighlighter = dummy.iterator().next();
}
editor.getScrollingModel().runActionOnScrollingFinished(() -> showReplacementPreview());
}
}
Aggregations