Search in sources :

Example 41 with RangeHighlighter

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);
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TIntArrayList(gnu.trove.TIntArrayList) ArrayList(java.util.ArrayList) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) TextRange(com.intellij.openapi.util.TextRange) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with RangeHighlighter

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);
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TextEditor(com.intellij.openapi.fileEditor.TextEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) HighlightManagerImpl(com.intellij.codeInsight.highlighting.HighlightManagerImpl)

Example 43 with RangeHighlighter

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;
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) ArrayList(java.util.ArrayList) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes)

Example 44 with RangeHighlighter

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;
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) Editor(com.intellij.openapi.editor.Editor)

Example 45 with RangeHighlighter

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());
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Editor(com.intellij.openapi.editor.Editor) FindResult(com.intellij.find.FindResult) HashSet(java.util.HashSet)

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