From 5cb74af1665fbb9a5c45dd907e824be6b8318f2d Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 21 Sep 2020 14:44:20 +0200 Subject: [PATCH] OutputFormatter: Prevent consecutive newlines from being ignored Amends b0cad9e9c7. Fixes: QTCREATORBUG-24668 Change-Id: I19a2ea71be91ded8f2c458537dae62a3021afe52 Reviewed-by: Christian Stenger Reviewed-by: hjk --- src/libs/utils/outputformatter.cpp | 7 +++++++ src/plugins/coreplugin/outputwindow.cpp | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libs/utils/outputformatter.cpp b/src/libs/utils/outputformatter.cpp index eb6e974dff2..d711569e7a8 100644 --- a/src/libs/utils/outputformatter.cpp +++ b/src/libs/utils/outputformatter.cpp @@ -287,6 +287,13 @@ void OutputFormatter::overridePostPrintAction(const PostPrintAction &postPrintAc void OutputFormatter::doAppendMessage(const QString &text, OutputFormat format) { QTextCharFormat charFmt = charFormat(format); + + // This might cause insertion of a newline character. + if (text.isEmpty()) { + append(text, charFmt); + return; + } + QList formattedText = parseAnsi(text, charFmt); const QString cleanLine = std::accumulate(formattedText.begin(), formattedText.end(), QString(), [](const FormattedText &t1, const FormattedText &t2) { return t1.text + t2.text; }); diff --git a/src/plugins/coreplugin/outputwindow.cpp b/src/plugins/coreplugin/outputwindow.cpp index 80fb566698b..4c9b162667c 100644 --- a/src/plugins/coreplugin/outputwindow.cpp +++ b/src/plugins/coreplugin/outputwindow.cpp @@ -624,7 +624,7 @@ void Internal::CorePlugin::testOutputFormatter() { const QString input = "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" "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"; const QString output = "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"