forked from qt-creator/qt-creator
CppEditor: Let doxygen continuation logic work also on asterisks
So that the closing part of a block comment gets properly aligned. Fixes: QTCREATORBUG-31256 Change-Id: I0ce18240c478deb7efce844f8a2c27c69d983447 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -387,6 +387,18 @@ void DoxygenTest::testBasic_data()
|
||||
" * \n"
|
||||
" */\n"
|
||||
"int a;\n") << int(CommandPrefix::Auto);
|
||||
|
||||
QTest::newRow("continuation_on_asterisk") << _(
|
||||
"bool preventFolding;\n"
|
||||
"/* leading comment\n"
|
||||
" * cont|*/\n"
|
||||
"int a;\n"
|
||||
) << _(
|
||||
"bool preventFolding;\n"
|
||||
"/* leading comment\n"
|
||||
" * cont\n"
|
||||
" */\n"
|
||||
"int a;\n") << int(CommandPrefix::Auto);
|
||||
}
|
||||
|
||||
void DoxygenTest::testBasic()
|
||||
|
@@ -264,20 +264,22 @@ bool handleDoxygenContinuation(QTextCursor &cursor,
|
||||
if (!currentLine.at(followinPos).isSpace())
|
||||
break;
|
||||
}
|
||||
if (followinPos == currentLine.length() // a)
|
||||
|| currentLine.at(followinPos) != QLatin1Char('*')) { // b)
|
||||
// So either a) the line ended after a '*' and we need to insert a continuation, or
|
||||
// b) we found the start of some text and we want to align the continuation to that.
|
||||
QString newLine(QLatin1Char('\n'));
|
||||
QTextCursor c(cursor);
|
||||
c.movePosition(QTextCursor::StartOfBlock);
|
||||
c.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, offset);
|
||||
newLine.append(c.selectedText());
|
||||
const bool isAtAsterisk = followinPos < currentLine.length()
|
||||
&& currentLine.at(followinPos) == '*';
|
||||
if (currentLine.at(offset) == QLatin1Char('/')) {
|
||||
if (leadingAsterisks)
|
||||
newLine.append(QLatin1String(" * "));
|
||||
if (leadingAsterisks) {
|
||||
if (isAtAsterisk)
|
||||
newLine.append(" ");
|
||||
else
|
||||
newLine.append(QLatin1String(" * "));
|
||||
} else {
|
||||
newLine.append(QLatin1String(" "));
|
||||
}
|
||||
offset += 3;
|
||||
} else {
|
||||
// If '*' is not within a comment, skip.
|
||||
@@ -288,18 +290,19 @@ bool handleDoxygenContinuation(QTextCursor &cursor,
|
||||
return false;
|
||||
|
||||
// ...otherwise do the continuation
|
||||
if (!isAtAsterisk) {
|
||||
int start = offset;
|
||||
while (offset < blockPos && currentLine.at(offset) == QLatin1Char('*'))
|
||||
++offset;
|
||||
const QChar ch = leadingAsterisks ? QLatin1Char('*') : QLatin1Char(' ');
|
||||
newLine.append(QString(offset - start, ch));
|
||||
}
|
||||
}
|
||||
for (; offset < blockPos && currentLine.at(offset) == ' '; ++offset)
|
||||
newLine.append(QLatin1Char(' '));
|
||||
cursor.insertText(newLine);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user