void () { if (myDisposed) { return; } final ConsoleView console = getConsoleNotNull(); console.clear(); myModel.processingStarted(); final String[] lines = myOriginalDocument != null ? myOriginalDocument.toString().split("\n") : ArrayUtilRt.EMPTY_STRING_ARRAY; int offset = 0; boolean caretPositioned = false; AnsiEscapeDecoder decoder = new AnsiEscapeDecoder(); for (String line : lines) { @SuppressWarnings("CodeBlock2Expr") final int printed = printMessageToConsole(line, (text, key) -> { decoder.escapeText(text, key, (chunk, attributes) -> { console.print(chunk, ConsoleViewContentType.getConsoleViewType(attributes)); }); }); if (printed > 0) { if (!caretPositioned) { if (Comparing.strEqual(myLineUnderSelection, line)) { caretPositioned = true; offset += myLineOffset != -1 ? myLineOffset : 0; } else { offset += printed; } } } } // we need this, because, document can change before actual scrolling, so offset may be already not at the end if (caretPositioned) { console.scrollTo(offset); } else { console.requestScrollingToEnd(); } }