diff --git a/src/plugins/cpptools/cppcodeformatter.cpp b/src/plugins/cpptools/cppcodeformatter.cpp index 4d98a0c1c25..1923d976e94 100644 --- a/src/plugins/cpptools/cppcodeformatter.cpp +++ b/src/plugins/cpptools/cppcodeformatter.cpp @@ -1437,8 +1437,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd break; case string_open: - *indentDepth = tokenPosition; - *paddingDepth = 0; + *paddingDepth = tokenPosition - *indentDepth; break; } @@ -1467,16 +1466,25 @@ void QtStyleCodeFormatter::adjustIndent(const QList &tokens, i // adjusting the indentDepth here instead of in enter() gives 'else if' the correct indentation // ### could be moved? - if (topState.type == substatement) + switch (topState.type) { + case substatement: *indentDepth += m_tabSettings.m_indentSize; - + break; // keep user-adjusted indent in multiline comments - if (topState.type == multiline_comment_start - || topState.type == multiline_comment_cont) { + case multiline_comment_start: + case multiline_comment_cont: if (!tokens.isEmpty()) { *indentDepth = column(tokens.at(0).bytesBegin()); return; } + break; + case string_open: + if (!tokenAt(0).isStringLiteral()) { + *paddingDepth = topState.savedPaddingDepth; + topState = previousState; + previousState = state(2); + } + break; } const int kind = tokenAt(0).kind(); diff --git a/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp b/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp index 1527f002574..c1ba2bd7c10 100644 --- a/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp +++ b/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp @@ -634,6 +634,8 @@ void tst_CodeFormatter::expressionContinuation1() << Line(" ~ << bar +") << Line(" ~ foo - blah(1)") << Line(" ~ << '?'") + << Line(" ~ << \"string\"") + << Line(" ~ \" concatenated\"") << Line(" ~ << \"\\n\";") << Line("}") ; @@ -2159,13 +2161,13 @@ void tst_CodeFormatter::strings() { QList data; data << Line("char *a = \"foo\"") - << Line(" \"bar\" \"why\"") - << Line(" \"baz\";") + << Line("~ \"bar\" \"why\"") + << Line("~ \"baz\";") << Line("void foo()") << Line("{") << Line(" func(1, 2, \"foo\"") - << Line(" \"bar\"") - << Line(" \"baz\", 4,") + << Line(" ~ \"bar\"") + << Line(" ~ \"baz\", 4,") << Line(" ~ 5, 6);") << Line("}") ;