OutputFormatter: Prevent consecutive newlines from being ignored

Amends b0cad9e9c7.

Fixes: QTCREATORBUG-24668
Change-Id: I19a2ea71be91ded8f2c458537dae62a3021afe52
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2020-09-21 14:44:20 +02:00
parent 0158dfcfd2
commit 5cb74af166
2 changed files with 9 additions and 2 deletions

View File

@@ -287,6 +287,13 @@ void OutputFormatter::overridePostPrintAction(const PostPrintAction &postPrintAc
void OutputFormatter::doAppendMessage(const QString &text, OutputFormat format) void OutputFormatter::doAppendMessage(const QString &text, OutputFormat format)
{ {
QTextCharFormat charFmt = charFormat(format); QTextCharFormat charFmt = charFormat(format);
// This might cause insertion of a newline character.
if (text.isEmpty()) {
append(text, charFmt);
return;
}
QList<FormattedText> formattedText = parseAnsi(text, charFmt); QList<FormattedText> formattedText = parseAnsi(text, charFmt);
const QString cleanLine = std::accumulate(formattedText.begin(), formattedText.end(), QString(), const QString cleanLine = std::accumulate(formattedText.begin(), formattedText.end(), QString(),
[](const FormattedText &t1, const FormattedText &t2) { return t1.text + t2.text; }); [](const FormattedText &t1, const FormattedText &t2) { return t1.text + t2.text; });

View File

@@ -624,7 +624,7 @@ void Internal::CorePlugin::testOutputFormatter()
{ {
const QString input = const QString input =
"B to be handled by B\r\n" "B to be handled by B\r\n"
"not to be handled\n" "not to be handled\n\n\n\n"
"A to be handled by A\n" "A to be handled by A\n"
"continuation for A\r\n" "continuation for A\r\n"
"B looks like B, but still continuation for A\r\n" "B looks like B, but still continuation for A\r\n"
@@ -636,7 +636,7 @@ void Internal::CorePlugin::testOutputFormatter()
"B to be handled by B\n"; "B to be handled by B\n";
const QString output = const QString output =
"handled by B\n" "handled by B\n"
"not to be handled\n" "not to be handled\n\n\n\n"
"handled by A\n" "handled by A\n"
"handled by A\n" "handled by A\n"
"handled by A\n" "handled by A\n"