public String toString() { TextChunk[] textChunks = getPresentation().getText(); StringBuilder result = new StringBuilder(); for (int j = 0; j < textChunks.length; j++) { if (j > 0) result.append("|"); TextChunk textChunk = textChunks[j]; result.append(textChunk); } return result.toString(); }
public void printToHistory(@NotNull final List<Pair<String, TextAttributes>> attributedText) { ApplicationManager.getApplication().assertIsDispatchThread(); if (LOG.isDebugEnabled()) { LOG.debug("printToHistory(): " + attributedText.size()); } final boolean scrollToEnd = shouldScrollHistoryToEnd(); final int[] offsets = new int[attributedText.size() + 1]; int i = 0; offsets[i] = 0; final StringBuilder sb = new StringBuilder(); for (final Pair<String, TextAttributes> pair : attributedText) { sb.append(StringUtil.convertLineSeparators(pair.getFirst())); offsets[++i] = sb.length(); } final DocumentEx history = myHistoryViewer.getDocument(); final int oldHistoryLength = history.getTextLength(); appendToHistoryDocument(history, sb.toString()); assert oldHistoryLength + offsets[i] == history.getTextLength() : "unexpected history length " + oldHistoryLength + " " + offsets[i] + " " + history.getTextLength(); LOG.debug("printToHistory(): text processed"); final MarkupModel markupModel = DocumentMarkupModel.forDocument(history, myProject, true); i = 0; for (final Pair<String, TextAttributes> pair : attributedText) { markupModel.addRangeHighlighter( oldHistoryLength + offsets[i], oldHistoryLength + offsets[i + 1], HighlighterLayer.SYNTAX, pair.getSecond(), HighlighterTargetArea.EXACT_RANGE); ++i; } LOG.debug("printToHistory(): markup added"); if (scrollToEnd) { scrollHistoryToEnd(); } queueUiUpdate(scrollToEnd); LOG.debug("printToHistory(): completed"); }