diff --git a/src/libs/qmljs/qmljscodeformatter.cpp b/src/libs/qmljs/qmljscodeformatter.cpp index 77bd008de68..7b1a5e250bb 100644 --- a/src/libs/qmljs/qmljscodeformatter.cpp +++ b/src/libs/qmljs/qmljscodeformatter.cpp @@ -167,6 +167,11 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block) case Signal: case Property: case Identifier: enter(expression_or_objectdefinition); break; + + // error recovery + case RightBracket: + case RightParenthesis: leave(true); break; + default: enter(expression); continue; } break; @@ -251,9 +256,14 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block) case expression_or_objectdefinition: switch (kind) { case Dot: - case Identifier: break; // need to become an objectdefinition_open in cases like "width: Qt.Foo {" - case LeftBrace: turnInto(objectdefinition_open); break; - default: enter(expression); continue; // really? identifier and more tokens might already be gone + case Identifier: break; // need to become an objectdefinition_open in cases like "width: Qt.Foo {" + case LeftBrace: turnInto(objectdefinition_open); break; + + // propagate 'leave' from expression state + case RightBracket: + case RightParenthesis: leave(); continue; + + default: enter(expression); continue; // really? identifier and more tokens might already be gone } break; case expression_or_label: diff --git a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp index 903e8f4a644..5a4411a1e9d 100644 --- a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp +++ b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp @@ -105,6 +105,7 @@ private Q_SLOTS: void multilineTernaryInProperty(); void multilineString(); void bug1(); + void bug2(); }; enum { DontCheck = -2, DontIndent = -1 }; @@ -1438,6 +1439,28 @@ void tst_QMLCodeFormatter::bug1() checkIndent(data); } +void tst_QMLCodeFormatter::bug2() +{ + QList data; + data << Line("Item {") + << Line(" x: a)") + << Line(" x: a) + 2") + << Line(" x: a == b)") + << Line(" x: a == b) + 5") + << Line(" x: a == b) ? c : d") + + << Line(" x: 1)") + << Line(" x: 1) + 2") + << Line(" x: 1 == 2)") + << Line(" x: 1 == 2) + 5") + << Line(" x: 1 == 2) ? c : d") + + << Line(" x: 1") + << Line("}") + ; + checkIndent(data); +} + QTEST_APPLESS_MAIN(tst_QMLCodeFormatter) #include "tst_qmlcodeformatter.moc"