summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libs/qmljs/qmljscodeformatter.cpp10
-rw-r--r--tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp15
2 files changed, 23 insertions, 2 deletions
diff --git a/src/libs/qmljs/qmljscodeformatter.cpp b/src/libs/qmljs/qmljscodeformatter.cpp
index c09ddbee14..484c0ddc32 100644
--- a/src/libs/qmljs/qmljscodeformatter.cpp
+++ b/src/libs/qmljs/qmljscodeformatter.cpp
@@ -254,8 +254,13 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
case expression_or_label:
switch (kind) {
- case Colon: turnInto(labelled_statement); break;
- default: enter(expression); continue;
+ case Colon: turnInto(labelled_statement); break;
+
+ // propagate 'leave' from expression state
+ case RightBracket:
+ case RightParenthesis: leave(); continue;
+
+ default: enter(expression); continue;
} break;
case ternary_op:
@@ -756,6 +761,7 @@ bool CodeFormatter::tryStatement()
case Function:
case Number:
case String:
+ case LeftParenthesis:
enter(expression);
// look at the token again
m_tokenIndex -= 1;
diff --git a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp
index af48a113e5..fa0c58b211 100644
--- a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp
+++ b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp
@@ -96,6 +96,7 @@ private Q_SLOTS:
void labelledStatements3();
void multilineTernaryInProperty();
void multilineString();
+ void bug1();
};
enum { DontCheck = -2, DontIndent = -1 };
@@ -1242,6 +1243,20 @@ void tst_QMLCodeFormatter::multilineString()
checkIndent(data);
}
+void tst_QMLCodeFormatter::bug1()
+{
+ QList<Line> data;
+ data << Line("Item {")
+ << Line(" x: {")
+ << Line(" if (a==a) {}")
+ << Line(" else (b==b) {}")
+ << Line(" foo()")
+ << Line(" }")
+ << Line("}")
+ ;
+ checkIndent(data);
+}
+
QTEST_APPLESS_MAIN(tst_QMLCodeFormatter)
#include "tst_qmlcodeformatter.moc"