diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 402f1d01eac..558efbee274 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -5627,6 +5627,26 @@ void CppEditorPlugin::test_quickfix_ExtractFunction_data() "{\n" " extracted(c);\n" "}\n"); + + QTest::newRow("if-block") + << _("inline void func()\n" + "{\n" + " int dummy = 0;\n" + " @{start}if@{end} (dummy < 10) {\n" + " ++dummy;\n" + " }\n" + "}\n") + << _("inline void extracted(int dummy)\n" + "{\n" + " if (dummy < 10) {\n" + " ++dummy;\n" + " }\n" + "}\n\n" + "inline void func()\n" + "{\n" + " int dummy = 0;\n" + " extracted(dummy);\n" + "}\n"); } void CppEditorPlugin::test_quickfix_ExtractFunction() diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index 8c65166aa1d..e259810182c 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -3885,7 +3885,7 @@ public: funcDef.append(QLatin1String(" const")); funcDecl.append(QLatin1String(" const")); } - funcDef.append(QLatin1String("\n{\n")); + funcDef.append(QLatin1String("\n{")); if (matchingClass) funcDecl.append(QLatin1String(";\n")); if (m_funcReturn) { @@ -3925,7 +3925,7 @@ public: QTC_ASSERT(tc.hasSelection(), return); position = tc.selectionEnd() + 1; change.clear(); - change.insert(position, extract); + change.insert(position, extract + '\n'); currentFile->setChangeSet(change); currentFile->appendReindentRange(ChangeSet::Range(position, position + 1)); currentFile->apply();