Search in sources :

Example 1 with HighlightManager

use of com.intellij.codeInsight.highlighting.HighlightManager in project intellij-community by JetBrains.

the class HighlighterUtil method highlightNode.

/**
     * Highlight a node in the editor.
     * @param editor the editor
     * @param node the node to be highlighted
     * @param attrs the attributes for the highlighter
     * @param cfg the plugin configuration
     * @return The created highlighter object
     */
public static RangeHighlighter highlightNode(Editor editor, final PsiElement node, TextAttributes attrs, Config cfg) {
    TextRange range;
    final PsiElement realElement;
    if ((node instanceof XmlTag) && cfg.isHighlightStartTagOnly()) {
        XmlTag tag = (XmlTag) node;
        realElement = MyPsiUtil.getNameElement(tag);
        range = realElement.getTextRange();
    } else {
        range = node.getTextRange();
        realElement = node;
    }
    // TODO: break at line boundaries
    final ArrayList<RangeHighlighter> highlighters = new ArrayList<>(1);
    final HighlightManager mgr = HighlightManager.getInstance(editor.getProject());
    mgr.addRangeHighlight(editor, range.getStartOffset(), range.getEndOffset(), attrs, false, highlighters);
    final RangeHighlighter rangeHighlighter = highlighters.get(0);
    if (cfg.isAddErrorStripe()) {
        rangeHighlighter.setErrorStripeMarkColor(attrs.getBackgroundColor());
        rangeHighlighter.setErrorStripeTooltip(formatTooltip(editor, realElement));
    } else {
        rangeHighlighter.setErrorStripeMarkColor(null);
    }
    return rangeHighlighter;
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 2 with HighlightManager

use of com.intellij.codeInsight.highlighting.HighlightManager in project intellij-community by JetBrains.

the class HighlighterUtil method removeHighlighter.

public static void removeHighlighter(Editor editor, RangeHighlighter h) {
    final HighlightManager mgr = HighlightManager.getInstance(editor.getProject());
    mgr.removeSegmentHighlighter(editor, h);
}
Also used : HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager)

Example 3 with HighlightManager

use of com.intellij.codeInsight.highlighting.HighlightManager in project intellij-community by JetBrains.

the class HighlighterUtil method clearHighlighters.

/**
     * Clear all highlighters in an editor that are set up by this class
     *
     * @param editor the editor
     */
public static void clearHighlighters(final Editor editor) {
    final List<RangeHighlighter> hl = editor.getUserData(HIGHLIGHTERS_KEY);
    if (hl != null) {
        if (purgeInvalidHighlighters(editor, hl)) {
            final HighlightManager mgr = HighlightManager.getInstance(editor.getProject());
            for (Iterator<RangeHighlighter> iterator = hl.iterator(); iterator.hasNext(); ) {
                RangeHighlighter highlighter = iterator.next();
                mgr.removeSegmentHighlighter(editor, highlighter);
                iterator.remove();
            }
        }
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager)

Example 4 with HighlightManager

use of com.intellij.codeInsight.highlighting.HighlightManager in project intellij-community by JetBrains.

the class XmlTagInplaceRenamer method addHighlights.

private static void addHighlights(List<TextRange> ranges, Editor editor, ArrayList<RangeHighlighter> highlighters) {
    EditorColorsManager colorsManager = EditorColorsManager.getInstance();
    final TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES);
    final HighlightManager highlightManager = HighlightManager.getInstance(editor.getProject());
    for (final TextRange range : ranges) {
        highlightManager.addOccurrenceHighlight(editor, range.getStartOffset(), range.getEndOffset(), attributes, 0, highlighters, null);
    }
    for (RangeHighlighter highlighter : highlighters) {
        highlighter.setGreedyToLeft(true);
        highlighter.setGreedyToRight(true);
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) TextRange(com.intellij.openapi.util.TextRange) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager)

Example 5 with HighlightManager

use of com.intellij.codeInsight.highlighting.HighlightManager in project intellij-community by JetBrains.

the class BaseIntroduceAction method extractFromExpression.

private void extractFromExpression(Editor e, final XPathExpression expression) {
    final Editor editor = (e instanceof EditorWindow) ? ((EditorWindow) e).getDelegate() : e;
    final HighlightManager highlightManager = HighlightManager.getInstance(expression.getProject());
    final Set<XPathExpression> matchingExpressions = RefactoringUtil.collectMatchingExpressions(expression);
    final List<XmlTag> otherMatches = new ArrayList<>(matchingExpressions.size());
    final ArrayList<RangeHighlighter> highlighters = new ArrayList<>(matchingExpressions.size() + 1);
    if (matchingExpressions.size() > 0) {
        final SelectionModel selectionModel = editor.getSelectionModel();
        highlightManager.addRangeHighlight(editor, selectionModel.getSelectionStart(), selectionModel.getSelectionEnd(), EditorColors.SEARCH_RESULT_ATTRIBUTES.getDefaultAttributes(), false, highlighters);
        for (XPathExpression expr : matchingExpressions) {
            final TextRange range = XsltCodeInsightUtil.getRangeInsideHostingFile(expr);
            highlightManager.addRangeHighlight(editor, range.getStartOffset(), range.getEndOffset(), EditorColors.SEARCH_RESULT_ATTRIBUTES.getDefaultAttributes(), false, highlighters);
            final XmlTag tag = PsiTreeUtil.getContextOfType(expr, XmlTag.class, true);
            assert tag != null;
            otherMatches.add(tag);
        }
    }
    final Settings dlg = getSettings(expression, matchingExpressions);
    if (dlg == null || dlg.isCanceled())
        return;
    if (getCommandName() != null) {
        new WriteCommandAction.Simple(e.getProject(), getCommandName()) {

            protected void run() throws Throwable {
                if (extractImpl(expression, matchingExpressions, otherMatches, dlg)) {
                    for (RangeHighlighter highlighter : highlighters) {
                        highlighter.dispose();
                    }
                }
            }
        }.execute();
    } else {
        extractImpl(expression, matchingExpressions, otherMatches, dlg);
    }
}
Also used : XPathExpression(org.intellij.lang.xpath.psi.XPathExpression) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) ArrayList(java.util.ArrayList) TextRange(com.intellij.openapi.util.TextRange) EditorWindow(com.intellij.injected.editor.EditorWindow) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) SelectionModel(com.intellij.openapi.editor.SelectionModel) Editor(com.intellij.openapi.editor.Editor) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)34 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)26 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)23 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)18 Editor (com.intellij.openapi.editor.Editor)9 Project (com.intellij.openapi.project.Project)9 TextRange (com.intellij.openapi.util.TextRange)9 ArrayList (java.util.ArrayList)8 PsiElement (com.intellij.psi.PsiElement)6 WindowManager (com.intellij.openapi.wm.WindowManager)4 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)3 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)3 XmlTag (com.intellij.psi.xml.XmlTag)3 Nullable (org.jetbrains.annotations.Nullable)3 TargetElementUtil (com.intellij.codeInsight.TargetElementUtil)2 FindManager (com.intellij.find.FindManager)2 FindModel (com.intellij.find.FindModel)2 EditorWindow (com.intellij.injected.editor.EditorWindow)2 Application (com.intellij.openapi.application.Application)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2