diff --git a/src/libs/qmljs/qmljsindenter.cpp b/src/libs/qmljs/qmljsindenter.cpp index 3df0f63097d7c41ef5b49239458f40d1e6f6cf32..7e1e50183c9861d03c20654d92287bdb672e1bbe 100644 --- a/src/libs/qmljs/qmljsindenter.cpp +++ b/src/libs/qmljs/qmljsindenter.cpp @@ -85,6 +85,12 @@ const int QmlJSIndenter::BigRoof = 400; QmlJSIndenter::QmlJSIndenter() : braceX(QRegExp(QLatin1String("^\\s*\\}\\s*(?:else|catch)\\b"))) + , caseOrDefault(QRegExp(QLatin1String( + "\\s*(?:" + "case\\b[^:]+|" + "default)" + "\\s*:.*"))) + { /* @@ -1007,12 +1013,16 @@ int QmlJSIndenter::indentForStandaloneLine() while (isContinuationLine()) readLine(); + int indentChange = - *yyBraceDepth; + if (caseOrDefault.exactMatch(*yyLine)) + ++indentChange; + /* Never trust lines containing only '{' or '}', as some people (Richard M. Stallman) format them weirdly. */ if (yyLine->trimmed().length() > 1) - return indentOfLine(*yyLine) - *yyBraceDepth * ppIndentSize; + return indentOfLine(*yyLine) + indentChange * ppIndentSize; } if (!readLine()) @@ -1071,12 +1081,7 @@ int QmlJSIndenter::indentForBottomLine(QTextBlock begin, QTextBlock end, QChar t */ indent -= ppIndentSize; } else if (okay(typedIn, QLatin1Char(':'))) { - QRegExp caseLabel( - QLatin1String("\\s*(?:case\\b(?:[^:]|::)+" - "|(?:default)\\s*" - ")?:.*")); - - if (caseLabel.exactMatch(bottomLine)) { + if (caseOrDefault.exactMatch(bottomLine)) { /* Move a case label (or the ':' in front of a constructor initialization list) one level to the diff --git a/src/libs/qmljs/qmljsindenter.h b/src/libs/qmljs/qmljsindenter.h index 52de5dfc08948501c9a86a4a5753bfd3c971e6e0..f63d08106fd17bdc3e6e83c87fb61c0cc73057ca 100644 --- a/src/libs/qmljs/qmljsindenter.h +++ b/src/libs/qmljs/qmljsindenter.h @@ -134,6 +134,7 @@ private: const bool *yyLeftBraceFollows; QRegExp braceX; + QRegExp caseOrDefault; }; } // namespace QmlJS diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index 53b8d047b05cd3cb31b8e1efb953a4eb4c368233..d2764ae2f96e06c3d67c87813c0e2c2bf813b72f 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -932,7 +932,8 @@ QString QmlJSTextEditor::wordUnderCursor() const bool QmlJSTextEditor::isElectricCharacter(const QChar &ch) const { if (ch == QLatin1Char('}') - || ch == QLatin1Char(']')) + || ch == QLatin1Char(']') + || ch == QLatin1Char(':')) return true; return false; }