diff --git a/autotests/input/indent/cstyle/doxygen11/expected b/autotests/input/indent/cstyle/doxygen11/expected new file mode 100644 --- /dev/null +++ b/autotests/input/indent/cstyle/doxygen11/expected @@ -0,0 +1,5 @@ +/** + * foo + * bar + */ +int foo = 1; diff --git a/autotests/input/indent/cstyle/doxygen11/input.js b/autotests/input/indent/cstyle/doxygen11/input.js new file mode 100644 --- /dev/null +++ b/autotests/input/indent/cstyle/doxygen11/input.js @@ -0,0 +1,7 @@ +v.setCursorPosition(0,0); +v.selectAll(); + +var r = v.selection(); +if (r.isValid()) { + v.align(r); +} diff --git a/autotests/input/indent/cstyle/doxygen11/origin b/autotests/input/indent/cstyle/doxygen11/origin new file mode 100644 --- /dev/null +++ b/autotests/input/indent/cstyle/doxygen11/origin @@ -0,0 +1,5 @@ +/** +* foo +* bar +*/ +int foo = 1; diff --git a/autotests/src/templatehandler_test.h b/autotests/src/templatehandler_test.h --- a/autotests/src/templatehandler_test.h +++ b/autotests/src/templatehandler_test.h @@ -36,6 +36,9 @@ void testSimpleMirror(); void testSimpleMirror_data(); + void testAlignC(); + void testAlignC_data(); + void testDefaults(); void testDefaults_data(); diff --git a/autotests/src/templatehandler_test.cpp b/autotests/src/templatehandler_test.cpp --- a/autotests/src/templatehandler_test.cpp +++ b/autotests/src/templatehandler_test.cpp @@ -137,6 +137,31 @@ QTest::newRow("several") << "${foo} ${foo} Foo ${foo}"; } +void TemplateHandlerTest::testAlignC() +{ + QFETCH(QString, input); + QFETCH(QString, expected); + + auto doc = new KTextEditor::DocumentPrivate(); + doc->setHighlightingMode("C"); + auto view = static_cast(doc->createView(nullptr)); + view->insertTemplate({0, 0}, input); + + QCOMPARE(doc->text(), expected); + + delete doc; +} + +void TemplateHandlerTest::testAlignC_data() +{ + QTest::addColumn("input"); + QTest::addColumn("expected"); + + QTest::newRow("one") << "/* ${foo} */" << "/* foo */"; + QTest::newRow("simple") << "/**\n* ${foo}\n*/" << "/**\n * foo\n */"; + QTest::newRow("complex") << "/**\n* @brief: ${...}\n* \n*/" << "/**\n * @brief: ...\n * \n */"; +} + void TemplateHandlerTest::testAdjacentRanges() { auto doc = new KTextEditor::DocumentPrivate(); diff --git a/src/script/data/indentation/cstyle.js b/src/script/data/indentation/cstyle.js --- a/src/script/data/indentation/cstyle.js +++ b/src/script/data/indentation/cstyle.js @@ -288,10 +288,6 @@ var char2 = document.charAt(currentLine, firstPos + 1); var currentString = document.line(currentLine); - // not in comment, no * copying - if (!isComment(currentLine, firstPos)) - return -1; - if (char1 == '/' && char2 == '*' && !currentString.contains("*/")) { indentation = document.firstVirtualColumn(currentLine); if (cfgAutoInsertStar) { @@ -311,7 +307,7 @@ } if (commentLine < 0) { indentation = document.firstVirtualColumn(currentLine); - } else if (document.startsWith(commentLine, "/*", true)) { + } else if (document.startsWith(commentLine, "/*", true) && !document.endsWith(commentLine, "*/", true)) { // found a /*, and all succeeding lines start with a *, so it's a comment block indentation = document.firstVirtualColumn(currentLine);