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;
}
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);
}
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();
}
}
}
}
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);
}
}
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);
}
}
Aggregations