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;
}
}

View File

@@ -83,8 +83,8 @@ public:
void setDemoteErrorsToWarnings(bool demote);
bool demoteErrorsToWarnings() const;
// line contains at most one line feed character, and if it does occur, it's the last character.
// Either way, the input is to be considered "complete" for parsing purposes.
// Represents a single line, without a trailing line feed character.
// The input is to be considered "complete" for parsing purposes.
virtual Result handleLine(const QString &line, OutputFormat format) = 0;
virtual bool handleLink(const QString &href) { Q_UNUSED(href); return false; }
@@ -183,6 +183,7 @@ private:
void append(const QString &text, const QTextCharFormat &format);
void initFormats();
void flushIncompleteLine();
void flushTrailingNewline();
void dumpIncompleteLine(const QString &line, OutputFormat format);
void clearLastLine();
QList<FormattedText> parseAnsi(const QString &text, const QTextCharFormat &format);

View File

@@ -57,7 +57,7 @@ LinuxIccParser::LinuxIccParser() :
// ".pch/Qt5Core.pchi.cpp": creating precompiled header file ".pch/Qt5Core.pchi"
// "animation/qabstractanimation.cpp": using precompiled header file ".pch/Qt5Core.pchi"
m_pchInfoLine.setPattern(QLatin1String("^\".*?\": (creating|using) precompiled header file \".*?\"\n$"));
m_pchInfoLine.setPattern(QLatin1String("^\".*?\": (creating|using) precompiled header file \".*?\"$"));
QTC_CHECK(m_pchInfoLine.isValid());
}

View File

@@ -111,11 +111,10 @@ TestTerminator::TestTerminator(OutputParserTester *t) :
Utils::OutputLineParser::Result TestTerminator::handleLine(const QString &line, Utils::OutputFormat type)
{
QTC_CHECK(line.endsWith('\n'));
if (type == Utils::StdOutFormat)
m_tester->m_receivedStdOutChildLine.append(line);
m_tester->m_receivedStdOutChildLine.append(line + '\n');
else
m_tester->m_receivedStdErrChildLine.append(line);
m_tester->m_receivedStdErrChildLine.append(line + '\n');
return Status::Done;
}

View File

@@ -511,6 +511,7 @@ void QtSupportPlugin::testQtOutputFormatter_appendMixedAssertAndAnsi()
"Blue\n";
formatter.appendMessage(inputText, StdOutFormat);
formatter.flush();
QCOMPARE(edit.toPlainText(), outputText);