diff --git a/src/plugins/cppeditor/cppqtstyleindenter.cpp b/src/plugins/cppeditor/cppqtstyleindenter.cpp index 778a8c229160682fa2de52bd99496ec1d95716f6..8c253c9b1cc384ef2d843a158c99bc0a2fa93db9 100644 --- a/src/plugins/cppeditor/cppqtstyleindenter.cpp +++ b/src/plugins/cppeditor/cppqtstyleindenter.cpp @@ -73,9 +73,16 @@ void CppQtStyleIndenter::indentBlock(QTextDocument *doc, int padding; codeFormatter.indentFor(block, &indent, &padding); - // only reindent the current line when typing electric characters if the - // indent is the same it would be if the line were empty if (isElectricCharacter(typedChar)) { + // : is only electric if the line has a 'case' or 'default' + if (typedChar == QLatin1Char(':') + && !(block.text().contains(QLatin1String("case")) + || block.text().contains(QLatin1String("default")))) { + return; + } + + // only reindent the current line when typing electric characters if the + // indent is the same it would be if the line were empty int newlineIndent; int newlinePadding; codeFormatter.indentForNewLineAfter(block.previous(), &newlineIndent, &newlinePadding);