private static void logInitial( @NotNull Editor editor, @NotNull int[] startOffsets, @NotNull int[] endOffsets, int indentSymbolsToStrip, int firstLineStartOffset) { if (!Registry.is("editor.richcopy.debug")) { return; } StringBuilder buffer = new StringBuilder(); Document document = editor.getDocument(); CharSequence text = document.getCharsSequence(); for (int i = 0; i < startOffsets.length; i++) { int start = startOffsets[i]; int lineStart = document.getLineStartOffset(document.getLineNumber(start)); int end = endOffsets[i]; int lineEnd = document.getLineEndOffset(document.getLineNumber(end)); buffer .append(" region #") .append(i) .append(": ") .append(start) .append('-') .append(end) .append(", text at range ") .append(lineStart) .append('-') .append(lineEnd) .append(": \n'") .append(text.subSequence(lineStart, lineEnd)) .append("'\n"); } if (buffer.length() > 0) { buffer.setLength(buffer.length() - 1); } LOG.info( String.format( "Preparing syntax-aware text. Given: %s selection, indent symbols to strip=%d, first line start offset=%d, selected text:%n%s", startOffsets.length > 1 ? "block" : "regular", indentSymbolsToStrip, firstLineStartOffset, buffer)); }
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"); }