Search in sources :

Example 21 with RangeHighlighterEx

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();
}
Also used : MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) CommonProcessors(com.intellij.util.CommonProcessors)

Example 22 with RangeHighlighterEx

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);
}
Also used : RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) JBColor(com.intellij.ui.JBColor) ArrayList(java.util.ArrayList) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EffectType(com.intellij.openapi.editor.markup.EffectType)

Example 23 with RangeHighlighterEx

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);
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) SMTRunnerConsoleView(com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView) ConsoleView(com.intellij.execution.ui.ConsoleView) ArrayList(java.util.ArrayList) Editor(com.intellij.openapi.editor.Editor) ConsoleViewImpl(com.intellij.execution.impl.ConsoleViewImpl) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RangeHighlighterEx (com.intellij.openapi.editor.ex.RangeHighlighterEx)23 MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)13 Document (com.intellij.openapi.editor.Document)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Editor (com.intellij.openapi.editor.Editor)5 MarkupModelListener (com.intellij.openapi.editor.impl.event.MarkupModelListener)5 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)5 NotNull (org.jetbrains.annotations.NotNull)5 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)4 Project (com.intellij.openapi.project.Project)4 RangeMarker (com.intellij.openapi.editor.RangeMarker)3 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)3 Pair (com.intellij.openapi.util.Pair)3 java.awt (java.awt)3 Nullable (org.jetbrains.annotations.Nullable)3 GutterMark (com.intellij.codeInsight.daemon.GutterMark)2 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)2 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)2 EditorEx (com.intellij.openapi.editor.ex.EditorEx)2