Skip to content

Commit

Permalink
improve indent for qml and javascript
Browse files Browse the repository at this point in the history
* qml binding assignments with arrow functions indent one level
* qml binding assignments with object literals indent one level
* js object literals indent one level
  • Loading branch information
arBmind committed Aug 31, 2021
1 parent 5780344 commit 4c9c137
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/libs/qmljs/qmljscodeformatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,25 +1200,33 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
if (parentState.type == expression
|| parentState.type == objectliteral_assignment) {
// undo the continuation indent of the expression
if (state(1).type == expression_or_label)
if (state(1).type == expression_or_label || state(1).type == binding_assignment)
*indentDepth = state(1).savedIndentDepth;
else
*indentDepth = parentState.savedIndentDepth;
*savedIndentDepth = *indentDepth;
}
else if (parentState.type == paren_open && state(1).type == expression) {
if (state(2).type == binding_assignment)
*savedIndentDepth = state(2).savedIndentDepth;
else
*savedIndentDepth = state(1).savedIndentDepth;
*indentDepth = *savedIndentDepth;
}
*indentDepth += m_indentSize;
break;


case statement_with_condition:
case try_statement:
case catch_statement:
case finally_statement:
case if_statement:
case do_statement:
case switch_statement:
if (firstToken || parentState.type == binding_assignment)
if (firstToken)
*savedIndentDepth = tokenPosition;
if (parentState.type == binding_assignment)
*savedIndentDepth = state(1).savedIndentDepth;
// ### continuation
*indentDepth = *savedIndentDepth; // + 2*m_indentSize;
// special case for 'else if'
Expand Down

0 comments on commit 4c9c137

Please sign in to comment.