use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class XPathEvalAction method execute.
private void execute(Editor editor) {
final Project project = editor.getProject();
final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (psiFile == null) {
return;
}
InputExpressionDialog.Context input;
XmlElement contextNode = null;
final Config cfg = XPathAppComponent.getInstance().getConfig();
do {
RangeHighlighter contextHighlighter = null;
if (cfg.isUseContextAtCursor()) {
// find out current context node
contextNode = MyPsiUtil.findContextNode(psiFile, editor);
if (contextNode != null) {
contextHighlighter = HighlighterUtil.highlightNode(editor, contextNode, cfg.getContextAttributes(), cfg);
}
}
if (contextNode == null) {
// in XPath data model, / is the document itself, including comments, PIs and the root element
contextNode = ((XmlFile) psiFile).getDocument();
if (contextNode == null) {
FileViewProvider fileViewProvider = psiFile.getViewProvider();
if (fileViewProvider instanceof TemplateLanguageFileViewProvider) {
Language dataLanguage = ((TemplateLanguageFileViewProvider) fileViewProvider).getTemplateDataLanguage();
PsiFile templateDataFile = fileViewProvider.getPsi(dataLanguage);
if (templateDataFile instanceof XmlFile)
contextNode = ((XmlFile) templateDataFile).getDocument();
}
}
}
input = inputXPathExpression(project, contextNode);
if (contextHighlighter != null) {
contextHighlighter.dispose();
}
if (input == null) {
return;
}
HighlighterUtil.clearHighlighters(editor);
} while (contextNode != null && evaluateExpression(input, contextNode, editor, cfg));
}
use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class HighlighterUtil method purgeInvalidHighlighters.
@SuppressWarnings({ "unchecked", "RawUseOfParameterizedType" })
private static boolean purgeInvalidHighlighters(Editor editor, List<RangeHighlighter> hl) {
final Set set = ContainerUtil.newIdentityTroveSet(Arrays.asList(editor.getMarkupModel().getAllHighlighters()));
boolean hasHighlighter = false;
for (Iterator<RangeHighlighter> iterator = hl.iterator(); iterator.hasNext(); ) {
final RangeHighlighter h = iterator.next();
if (!h.isValid() || !set.contains(h)) {
iterator.remove();
} else {
hasHighlighter = true;
}
}
return hasHighlighter;
}
use of com.intellij.openapi.editor.markup.RangeHighlighter 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.openapi.editor.markup.RangeHighlighter 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.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.
the class ProcessWithConsoleRunner method getHighlightedStringsInConsole.
/**
* Gets highlighted information from test console. Some parts of output (like file links) may be highlighted, and you need to check them.
*
* @return pair of [[ranges], [texts]] where range is [from,to] in doc. for each region, and "text" is text extracted from this region.
* For example assume that in document "spam eggs ham" words "ham" and "spam" are highlighted.
* You should have 2 ranges (0, 4) and (10, 13) and 2 strings (spam and ham)
*/
@NotNull
public Pair<List<Pair<Integer, Integer>>, List<String>> getHighlightedStringsInConsole() {
final List<String> resultStrings = new ArrayList<>();
final List<Pair<Integer, Integer>> resultRanges = new ArrayList<>();
ApplicationManager.getApplication().invokeAndWait(() -> {
myConsole.flushDeferredText();
final Editor editor = myConsole.getEditor();
for (final RangeHighlighter highlighter : editor.getMarkupModel().getAllHighlighters()) {
if (highlighter instanceof RangeHighlighterEx) {
final int start = ((RangeHighlighterEx) highlighter).getAffectedAreaStartOffset();
final int end = ((RangeHighlighterEx) highlighter).getAffectedAreaEndOffset();
resultRanges.add(Pair.create(start, end));
resultStrings.add(editor.getDocument().getText().substring(start, end));
}
}
}, ModalityState.NON_MODAL);
return Pair.create(resultRanges, resultStrings);
}
Aggregations