Search in sources :

Example 76 with TextAttributes

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

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

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

the class LivePreview method highlightUsages.

private void highlightUsages() {
    if (mySearchResults.getEditor() == null)
        return;
    if (mySearchResults.getMatchesCount() >= mySearchResults.getMatchesLimit())
        return;
    for (FindResult range : mySearchResults.getOccurrences()) {
        if (range.getEndOffset() > mySearchResults.getEditor().getDocument().getTextLength())
            continue;
        TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES);
        if (range.getLength() == 0) {
            attributes = attributes.clone();
            attributes.setEffectType(EffectType.BOXED);
            attributes.setEffectColor(attributes.getBackgroundColor());
        }
        if (mySearchResults.isExcluded(range)) {
            highlightRange(range, strikeout(), myHighlighters);
        } else {
            highlightRange(range, attributes, myHighlighters);
        }
    }
    updateInSelectionHighlighters();
    if (!myListeningSelection) {
        mySearchResults.getEditor().getSelectionModel().addSelectionListener(this);
        myListeningSelection = true;
    }
}
Also used : TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) FindResult(com.intellij.find.FindResult)

Example 79 with TextAttributes

use of com.intellij.openapi.editor.markup.TextAttributes 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)

Example 80 with TextAttributes

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

the class CallerChooserBase method updateEditorTexts.

private void updateEditorTexts(final MethodNodeBase<M> node) {
    final MethodNodeBase<M> parentNode = getCalleeNode(node);
    final MethodNodeBase<M> callerNode = getCallerNode(node);
    final String callerText = node != myRoot ? getText(callerNode.getMethod()) : getEmptyCallerText();
    final Document callerDocument = myCallerEditor.getDocument();
    final String calleeText = node != myRoot ? getText(parentNode.getMethod()) : getEmptyCalleeText();
    final Document calleeDocument = myCalleeEditor.getDocument();
    ApplicationManager.getApplication().runWriteAction(() -> {
        callerDocument.setText(callerText);
        calleeDocument.setText(calleeText);
    });
    final M caller = callerNode.getMethod();
    final PsiElement callee = parentNode != null ? parentNode.getElementToSearch() : null;
    if (caller != null && caller.isPhysical() && callee != null) {
        HighlightManager highlighter = HighlightManager.getInstance(myProject);
        EditorColorsManager colorManager = EditorColorsManager.getInstance();
        TextAttributes attributes = colorManager.getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES);
        int start = getStartOffset(caller);
        for (PsiElement element : findElementsToHighlight(caller, callee)) {
            highlighter.addRangeHighlight(myCallerEditor, element.getTextRange().getStartOffset() - start, element.getTextRange().getEndOffset() - start, attributes, false, null);
        }
    }
}
Also used : HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement)

Aggregations

TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)205 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)40 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)31 NotNull (org.jetbrains.annotations.NotNull)29 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)28 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)26 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)26 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)23 TextRange (com.intellij.openapi.util.TextRange)21 Nullable (org.jetbrains.annotations.Nullable)21 ArrayList (java.util.ArrayList)19 Editor (com.intellij.openapi.editor.Editor)18 Project (com.intellij.openapi.project.Project)17 PsiElement (com.intellij.psi.PsiElement)12 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 JBColor (com.intellij.ui.JBColor)10 Document (com.intellij.openapi.editor.Document)9 ContainerUtil (com.intellij.util.containers.ContainerUtil)9 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)8