OutputFormatter: Fix flushing a pending line feed

... for the edge case of a lone carriage return occurring in the output.
Amends b0cad9e9c7.
Also adds missing adaptations to the unit test.

Change-Id: I219b24b8fb41bb0fcea9f677cd79286d03b130c2
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2020-09-11 15:52:53 +02:00
parent 6ab7013579
commit 226982b7b0
2 changed files with 4 additions and 3 deletions

View File

@@ -429,6 +429,7 @@ void OutputFormatter::append(const QString &text, const QTextCharFormat &format)
{
if (!plainTextEdit())
return;
flushTrailingNewline();
int startPos = 0;
int crPos = -1;
while ((crPos = text.indexOf('\r', startPos)) >= 0) {
@@ -437,7 +438,6 @@ 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);
}