forked from qt-creator/qt-creator
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:
@@ -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);
|
||||
}
|
||||
|
@@ -590,7 +590,7 @@ class TestFormatterA : public OutputLineParser
|
||||
private:
|
||||
Result handleLine(const QString &text, OutputFormat) override
|
||||
{
|
||||
static const QString replacement = "handled by A\n";
|
||||
static const QString replacement = "handled by A";
|
||||
if (m_handling) {
|
||||
if (text.startsWith("A")) {
|
||||
m_handling = false;
|
||||
@@ -615,7 +615,7 @@ private:
|
||||
Result handleLine(const QString &text, OutputFormat) override
|
||||
{
|
||||
if (text.startsWith("B"))
|
||||
return {Status::Done, {}, QString("handled by B\n")};
|
||||
return {Status::Done, {}, QString("handled by B")};
|
||||
return Status::NotHandled;
|
||||
}
|
||||
};
|
||||
@@ -656,6 +656,7 @@ void Internal::CorePlugin::testOutputFormatter()
|
||||
formatter.setLineParsers({new TestFormatterB, new TestFormatterA});
|
||||
formatter.appendMessage(input.left(i), StdOutFormat);
|
||||
formatter.appendMessage(input.mid(i), StdOutFormat);
|
||||
formatter.flush();
|
||||
QCOMPARE(textEdit.toPlainText(), output);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user