OutputFormatter: Re-add handling of stand-alone carriage return

Amends 054e7c2164.

Change-Id: If8ee94c3377ff71c8b5d87d431d8b6a2c87bb6f6
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Christian Kandeler
2020-03-30 15:49:15 +02:00
parent d3cf1549ee
commit 4e199eed8d
2 changed files with 12 additions and 2 deletions

View File

@@ -108,8 +108,16 @@ QList<FormattedText> OutputFormatter::parseAnsi(const QString &text, const QText
void OutputFormatter::append(const QString &text, const QTextCharFormat &format)
{
if (!text.isEmpty())
d->cursor.insertText(text, format);
int startPos = 0;
int crPos = -1;
while ((crPos = text.indexOf('\r', startPos)) >= 0) {
d->cursor.insertText(text.mid(startPos, crPos - startPos), format);
d->cursor.clearSelection();
d->cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
startPos = crPos + 1;
}
if (startPos < text.count())
d->cursor.insertText(text.mid(startPos), format);
}
QTextCursor &OutputFormatter::cursor() const

View File

@@ -555,6 +555,7 @@ void Internal::CorePlugin::testOutputFormatter()
"A next A\n"
"A end of next A\n"
" A trick\r\n"
"line with \r embedded carriage return\n"
"B to be handled by B\n";
const QString output =
"handled by B\n"
@@ -566,6 +567,7 @@ void Internal::CorePlugin::testOutputFormatter()
"handled by A\n"
"handled by A\n"
" A trick\n"
" embedded carriage return\n"
"handled by B\n";
TestFormatterA formatterA;
TestFormatterB formatterB;