OutputFormatter: Fix visual glitch

When inserting a line into an output window, we have to delay appending
the line feed character. Otherwise strange visual effects appear under
certain circumstances.
I have no idea why.

Fixes: QTCREATORBUG-24411
Change-Id: If8842ae4d9db36d514996b1f34dcca0432fafbfc
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Christian Kandeler
2020-09-04 16:51:38 +02:00
parent f73f11d8c6
commit b0cad9e9c7
5 changed files with 20 additions and 7 deletions

View File

@@ -216,6 +216,7 @@ public:
PostPrintAction postPrintAction;
bool boldFontEnabled = true;
bool prependCarriageReturn = false;
bool prependLineFeed = false;
};
OutputFormatter::OutputFormatter() : d(new Private) { }
@@ -436,6 +437,7 @@ void OutputFormatter::append(const QString &text, const QTextCharFormat &format)
d->cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
startPos = crPos + 1;
}
flushTrailingNewline();
if (startPos < text.count())
d->cursor.insertText(text.mid(startPos), format);
}
@@ -495,6 +497,14 @@ void OutputFormatter::flushIncompleteLine()
d->incompleteLine.first.clear();
}
void Utils::OutputFormatter::flushTrailingNewline()
{
if (d->prependLineFeed) {
d->cursor.insertText("\n");
d->prependLineFeed = false;
}
}
void OutputFormatter::dumpIncompleteLine(const QString &line, OutputFormat format)
{
if (line.isEmpty())
@@ -560,6 +570,7 @@ void OutputFormatter::flush()
{
if (!d->incompleteLine.first.isEmpty())
flushIncompleteLine();
flushTrailingNewline();
d->escapeCodeHandler.endFormatScope();
for (OutputLineParser * const p : qAsConst(d->lineParsers))
p->flush();
@@ -641,7 +652,8 @@ void OutputFormatter::appendMessage(const QString &text, OutputFormat format)
dumpIncompleteLine(out.mid(startPos), format);
break;
}
doAppendMessage(out.mid(startPos, eolPos - startPos + 1), format);
doAppendMessage(out.mid(startPos, eolPos - startPos), format);
d->prependLineFeed = true;
startPos = eolPos + 1;
}
}