Search in sources :

Example 96 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter in project intellij-community by JetBrains.

the class PythonConsoleView method doAddPromptToHistory.

protected final void doAddPromptToHistory(boolean isMainPrompt) {
    flushDeferredText();
    EditorEx viewer = getHistoryViewer();
    DocumentEx document = viewer.getDocument();
    RangeHighlighter highlighter = getHistoryViewer().getMarkupModel().addRangeHighlighter(document.getTextLength(), document.getTextLength(), 0, null, HighlighterTargetArea.EXACT_RANGE);
    final String prompt;
    if (isMainPrompt) {
        prompt = myPromptView.getMainPrompt();
        print(prompt + " ", myPromptView.getPromptAttributes());
    } else {
        prompt = myPromptView.getIndentPrompt();
        //todo should really be myPromptView.getPromptAttributes() output type
        //but in that case flushing doesn't get handled correctly. Take a look at it later
        print(prompt + " ", ConsoleViewContentType.USER_INPUT);
    }
    highlighter.putUserData(PyConsoleCopyHandler.PROMPT_LENGTH_MARKER, prompt.length() + 1);
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) EditorEx(com.intellij.openapi.editor.ex.EditorEx)

Example 97 with RangeHighlighter

use of com.intellij.openapi.editor.markup.RangeHighlighter 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

RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)97 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)26 TextRange (com.intellij.openapi.util.TextRange)22 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)18 Editor (com.intellij.openapi.editor.Editor)15 ArrayList (java.util.ArrayList)15 NotNull (org.jetbrains.annotations.NotNull)15 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)10 Project (com.intellij.openapi.project.Project)10 RelativePoint (com.intellij.ui.awt.RelativePoint)8 Nullable (org.jetbrains.annotations.Nullable)8 Document (com.intellij.openapi.editor.Document)7 EditorEx (com.intellij.openapi.editor.ex.EditorEx)7 MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)7 MarkupModel (com.intellij.openapi.editor.markup.MarkupModel)7 PsiElement (com.intellij.psi.PsiElement)6 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)5 EditorWindow (com.intellij.injected.editor.EditorWindow)4 Result (com.intellij.openapi.application.Result)4 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)4