forked from qt-creator/qt-creator
qmljs: indent expression in if condition and indent lambda expressions
* indent expressions (like function defs) in if condition fixes QTCREATORBUG-7243 Change-Id: I61197317a8dcba72a45b660600711748e2e2b962 Reviewed-by: Christian Kamm <kamm@incasoftware.de> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
committed by
Fawzi Mohamed
parent
9bf654743e
commit
66eb27e687
@@ -407,16 +407,10 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
|
||||
break;
|
||||
|
||||
case condition_open:
|
||||
if (tryInsideExpression())
|
||||
break;
|
||||
switch (kind) {
|
||||
case RightParenthesis: turnInto(substatement); break;
|
||||
case LeftParenthesis: enter(condition_paren_open); break;
|
||||
} break;
|
||||
|
||||
// paren nesting
|
||||
case condition_paren_open:
|
||||
switch (kind) {
|
||||
case RightParenthesis: leave(); break;
|
||||
case LeftParenthesis: enter(condition_paren_open); break;
|
||||
} break;
|
||||
|
||||
case switch_statement:
|
||||
@@ -1131,7 +1125,6 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
|
||||
case signal_arglist_open:
|
||||
case function_arglist_open:
|
||||
case paren_open:
|
||||
case condition_paren_open:
|
||||
if (!lastToken)
|
||||
*indentDepth = tokenPosition + 1;
|
||||
else
|
||||
|
||||
@@ -154,7 +154,6 @@ public: // must be public to make Q_GADGET introspection work
|
||||
else_clause, // The else line of an if-else construct.
|
||||
|
||||
condition_open, // Start of a condition in 'if', 'while', entered after opening paren
|
||||
condition_paren_open, // After an lparen in a condition
|
||||
|
||||
substatement, // The first line after a conditional or loop construct.
|
||||
substatement_open, // The brace that opens a substatement block.
|
||||
|
||||
@@ -75,7 +75,8 @@ private Q_SLOTS:
|
||||
void ifStatementWithBraces3();
|
||||
void ifStatementMixed();
|
||||
void ifStatementAndComments();
|
||||
void ifStatementLongCondition();
|
||||
void ifStatementLongCondition1();
|
||||
void ifStatementLongCondition2();
|
||||
void moreIfThenElse();
|
||||
void strayElse();
|
||||
void oneLineIf();
|
||||
@@ -941,7 +942,7 @@ void tst_QMLCodeFormatter::ifStatementAndComments()
|
||||
checkIndent(data);
|
||||
}
|
||||
|
||||
void tst_QMLCodeFormatter::ifStatementLongCondition()
|
||||
void tst_QMLCodeFormatter::ifStatementLongCondition1()
|
||||
{
|
||||
QList<Line> data;
|
||||
data << Line("Rectangle {")
|
||||
@@ -958,6 +959,23 @@ void tst_QMLCodeFormatter::ifStatementLongCondition()
|
||||
checkIndent(data);
|
||||
}
|
||||
|
||||
void tst_QMLCodeFormatter::ifStatementLongCondition2()
|
||||
{
|
||||
QList<Line> data;
|
||||
data << Line("function test() {")
|
||||
<< Line(" if (foo(function() {")
|
||||
<< Line(" if (xx) {")
|
||||
<< Line(" yy = yy - 1")
|
||||
<< Line(" } else {")
|
||||
<< Line(" yy = yy + 1")
|
||||
<< Line(" }")
|
||||
<< Line(" })) {")
|
||||
<< Line(" zz = !zz")
|
||||
<< Line(" }")
|
||||
<< Line("}");
|
||||
checkIndent(data);
|
||||
}
|
||||
|
||||
void tst_QMLCodeFormatter::strayElse()
|
||||
{
|
||||
QList<Line> data;
|
||||
|
||||
Reference in New Issue
Block a user