forked from qt-creator/qt-creator
TextEditor: Prevent unwanted reflowing of doxygen comments
... in rewrapParagraph(). One could argue that this functionality is only for pure text and should not be used on code, but since it was apparently contributed with doxygen in mind, we might as well go out of our way a bit to support it a little better. The simple approach here is to treat a doxygen command at the start of a line as the end of the reflow region. Fixes: QTCREATORBUG-9739 Change-Id: I5affee9c441bd9e862bdaf38930fcf8e770b6d97 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -88,6 +88,7 @@
|
||||
#include <QPrinter>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QDrag>
|
||||
#include <QRegularExpression>
|
||||
#include <QSequentialAnimationGroup>
|
||||
#include <QScreen>
|
||||
#include <QScrollBar>
|
||||
@@ -7195,26 +7196,35 @@ void TextEditorWidget::rewrapParagraph()
|
||||
QTextCursor nextBlock = cursor;
|
||||
QString commonPrefix;
|
||||
|
||||
const QString doxygenPrefix("^\\s*(?:///|/\\*\\*|/\\*\\!|\\*)?[ *]+");
|
||||
if (nextBlock.movePosition(QTextCursor::NextBlock))
|
||||
{
|
||||
QString nText = nextBlock.block().text();
|
||||
int maxLength = qMin(text.length(), nText.length());
|
||||
|
||||
const auto hasDoxygenPrefix = [&] {
|
||||
static const QRegularExpression pattern(doxygenPrefix);
|
||||
return pattern.match(commonPrefix).hasMatch();
|
||||
};
|
||||
|
||||
for (int i = 0; i < maxLength; ++i) {
|
||||
const QChar ch = text.at(i);
|
||||
|
||||
if (ch != nText[i] || ch.isLetterOrNumber())
|
||||
if (ch != nText[i] || ch.isLetterOrNumber()
|
||||
|| ((ch == '@' || ch == '\\' ) && hasDoxygenPrefix())) {
|
||||
break;
|
||||
}
|
||||
commonPrefix.append(ch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Find end of paragraph.
|
||||
const QRegularExpression immovableDoxygenCommand(doxygenPrefix + "[@\\\\].*");
|
||||
QTC_CHECK(immovableDoxygenCommand.isValid());
|
||||
while (cursor.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor)) {
|
||||
QString text = cursor.block().text();
|
||||
|
||||
if (!text.contains(anyLettersOrNumbers))
|
||||
if (!text.contains(anyLettersOrNumbers) || immovableDoxygenCommand.match(text).hasMatch())
|
||||
break;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user