QmlJS: Fix object literal indent in property initializers.

This commit is contained in:
Christian Kamm
2011-04-21 12:56:37 +02:00
parent b0da6a1e6c
commit 8d4d88f072
4 changed files with 54 additions and 6 deletions

View File

@@ -101,7 +101,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
switch (newState) {
case objectdefinition_open: {
// special case for things like "gradient: Gradient {"
if (parentState.type == binding_assignment)
if (parentState.type == binding_assignment || parentState.type == property_initializer)
*savedIndentDepth = state(1).savedIndentDepth;
if (firstToken)
@@ -117,6 +117,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
break;
case binding_assignment:
case property_initializer:
case objectliteral_assignment:
if (lastToken)
*indentDepth = *savedIndentDepth + 4;
@@ -133,6 +134,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
// ternary already adjusts indents nicely
if (parentState.type != expression_or_objectdefinition
&& parentState.type != binding_assignment
&& parentState.type != property_initializer
&& parentState.type != ternary_op) {
*indentDepth += 2 * m_indentSize;
}
@@ -153,7 +155,8 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
break;
case bracket_open:
if (parentState.type == expression && state(1).type == binding_assignment) {
if (parentState.type == expression && (state(1).type == binding_assignment
|| state(1).type == property_initializer)) {
*savedIndentDepth = state(2).savedIndentDepth;
*indentDepth = *savedIndentDepth + m_indentSize;
} else if (!lastToken) {
@@ -205,7 +208,9 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
break;
case objectliteral_open:
if (parentState.type == expression || parentState.type == objectliteral_assignment) {
if (parentState.type == expression
|| parentState.type == objectliteral_assignment
|| parentState.type == property_initializer) {
// undo the continuation indent of the expression
*indentDepth = parentState.savedIndentDepth;
*savedIndentDepth = *indentDepth;
@@ -288,6 +293,7 @@ void QtStyleCodeFormatter::adjustIndent(const QList<Token> &tokens, int lexerSta
case LeftBrace:
if (topState.type == substatement
|| topState.type == binding_assignment
|| topState.type == property_initializer
|| topState.type == case_cont) {
*indentDepth = topState.savedIndentDepth;
}