QmlJS: Fix indent of object literals.

Reviewed-by: Roberto Raggi
This commit is contained in:
Christian Kamm
2011-04-21 12:21:23 +02:00
parent e3928941ee
commit d0d0a8c07e
4 changed files with 92 additions and 5 deletions

View File

@@ -117,6 +117,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
break;
case binding_assignment:
case objectliteral_assignment:
if (lastToken)
*indentDepth = *savedIndentDepth + 4;
else
@@ -203,6 +204,16 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
*indentDepth = *savedIndentDepth + m_indentSize;
break;
case objectliteral_open:
if (parentState.type == expression || parentState.type == objectliteral_assignment) {
// undo the continuation indent of the expression
*indentDepth = parentState.savedIndentDepth;
*savedIndentDepth = *indentDepth;
}
*indentDepth += m_indentSize;
break;
case statement_with_condition:
case statement_with_block:
case if_statement:
@@ -290,7 +301,8 @@ void QtStyleCodeFormatter::adjustIndent(const QList<Token> &tokens, int lexerSta
const int type = state(i).type;
if (type == objectdefinition_open
|| type == jsblock_open
|| type == substatement_open) {
|| type == substatement_open
|| type == objectliteral_open) {
*indentDepth = state(i).savedIndentDepth;
break;
}