use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.
the class RangeMarkerTest method testRangeHighlighterLinesInRangeForLongLinePerformance.
public void testRangeHighlighterLinesInRangeForLongLinePerformance() throws Exception {
final int N = 50000;
Document document = EditorFactory.getInstance().createDocument(StringUtil.repeatSymbol('x', 2 * N));
final MarkupModelEx markupModel = (MarkupModelEx) DocumentMarkupModel.forDocument(document, ourProject, true);
for (int i = 0; i < N - 1; i++) {
markupModel.addRangeHighlighter(2 * i, 2 * i + 1, 0, null, HighlighterTargetArea.EXACT_RANGE);
}
markupModel.addRangeHighlighter(N / 2, N / 2 + 1, 0, null, HighlighterTargetArea.LINES_IN_RANGE);
PlatformTestUtil.startPerformanceTest("slow highlighters lookup", (int) (N * Math.log(N) / 1000), () -> {
List<RangeHighlighterEx> list = new ArrayList<>();
CommonProcessors.CollectProcessor<RangeHighlighterEx> coll = new CommonProcessors.CollectProcessor<>(list);
for (int i = 0; i < N - 1; i++) {
list.clear();
markupModel.processRangeHighlightersOverlappingWith(2 * i, 2 * i + 1, coll);
// 1 line plus one exact range marker
assertEquals(2, list.size());
}
}).useLegacyScaling().assertTiming();
}
use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.
the class ImmediatePainter method updateAttributes.
// TODO Unify with com.intellij.openapi.editor.impl.view.IterationState.setAttributes
private static void updateAttributes(final EditorImpl editor, final TextAttributes attributes, final List<RangeHighlighterEx> highlighters) {
if (highlighters.size() > 1) {
ContainerUtil.quickSort(highlighters, IterationState.BY_LAYER_THEN_ATTRIBUTES);
}
TextAttributes syntax = attributes;
TextAttributes caretRow = editor.getCaretModel().getTextAttributes();
final int size = highlighters.size();
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < size; i++) {
RangeHighlighterEx highlighter = highlighters.get(i);
if (highlighter.getTextAttributes() == TextAttributes.ERASE_MARKER) {
syntax = null;
}
}
final List<TextAttributes> cachedAttributes = new ArrayList<>();
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < size; i++) {
RangeHighlighterEx highlighter = highlighters.get(i);
if (caretRow != null && highlighter.getLayer() < HighlighterLayer.CARET_ROW) {
cachedAttributes.add(caretRow);
caretRow = null;
}
if (syntax != null && highlighter.getLayer() < HighlighterLayer.SYNTAX) {
cachedAttributes.add(syntax);
syntax = null;
}
TextAttributes textAttributes = highlighter.getTextAttributes();
if (textAttributes != null && textAttributes != TextAttributes.ERASE_MARKER) {
cachedAttributes.add(textAttributes);
}
}
if (caretRow != null)
cachedAttributes.add(caretRow);
if (syntax != null)
cachedAttributes.add(syntax);
Color foreground = null;
Color background = null;
Color effect = null;
EffectType effectType = null;
int fontType = 0;
//noinspection ForLoopReplaceableByForEach, Duplicates
for (int i = 0; i < cachedAttributes.size(); i++) {
TextAttributes attrs = cachedAttributes.get(i);
if (foreground == null) {
foreground = attrs.getForegroundColor();
}
if (background == null) {
background = attrs.getBackgroundColor();
}
if (fontType == Font.PLAIN) {
fontType = attrs.getFontType();
}
if (effect == null) {
effect = attrs.getEffectColor();
effectType = attrs.getEffectType();
}
}
if (foreground == null)
foreground = editor.getForegroundColor();
if (background == null)
background = editor.getBackgroundColor();
if (effectType == null)
effectType = EffectType.BOXED;
TextAttributes defaultAttributes = editor.getColorsScheme().getAttributes(HighlighterColors.TEXT);
if (fontType == Font.PLAIN)
fontType = defaultAttributes == null ? Font.PLAIN : defaultAttributes.getFontType();
attributes.setAttributes(foreground, background, effect, null, effectType, fontType);
}
use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.
the class PyUnitTestTask method getHighlightedStrings.
/**
* 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 final Pair<List<Pair<Integer, Integer>>, List<String>> getHighlightedStrings() {
final ConsoleView console = myConsoleView.getConsole();
assert console instanceof ConsoleViewImpl : "Console has no editor!";
final ConsoleViewImpl consoleView = (ConsoleViewImpl) console;
final Editor editor = consoleView.getEditor();
final List<String> resultStrings = new ArrayList<>();
final List<Pair<Integer, Integer>> resultRanges = new ArrayList<>();
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
/**
* To fetch data from console we need to flush it first.
* It works locally, but does not work on TC (reasons are not clear yet and need to be investigated).
* So, we flush it explicitly to make test run on TC.
*/
consoleView.flushDeferredText();
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));
}
}
}
});
final String message = String.format("Following output is searched for hightlighed strings: %s \n", editor.getDocument().getText());
Logger.getInstance(getClass()).warn(message);
return Pair.create(resultRanges, resultStrings);
}
Aggregations