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