forked from qt-creator/qt-creator
TextEditor: do not collapse doc comments in the beginning of a file
The auto fold license header functionality also automatically folds documentation comments. Automatically collapsing documentation comments is never correct in the first place so just skip the fold when encounter a documentation marker in the first comment. Fixes: QTCREATORBUG-29900 Change-Id: If0dd7842804f3ff0bcd725b54413e9568d5b5ab3 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -1919,6 +1919,7 @@ void TextEditorWidgetPrivate::foldLicenseHeader()
|
|||||||
if (TextDocumentLayout::canFold(block) && block.next().isVisible()) {
|
if (TextDocumentLayout::canFold(block) && block.next().isVisible()) {
|
||||||
const QString trimmedText = text.trimmed();
|
const QString trimmedText = text.trimmed();
|
||||||
QStringList commentMarker;
|
QStringList commentMarker;
|
||||||
|
QStringList docMarker;
|
||||||
if (auto highlighter = qobject_cast<Highlighter *>(
|
if (auto highlighter = qobject_cast<Highlighter *>(
|
||||||
q->textDocument()->syntaxHighlighter())) {
|
q->textDocument()->syntaxHighlighter())) {
|
||||||
const Highlighter::Definition def = highlighter->definition();
|
const Highlighter::Definition def = highlighter->definition();
|
||||||
@@ -1929,11 +1930,19 @@ void TextEditorWidgetPrivate::foldLicenseHeader()
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
commentMarker = QStringList({"/*", "#"});
|
commentMarker = QStringList({"/*", "#"});
|
||||||
|
docMarker = QStringList({"/*!", "/**"});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils::anyOf(commentMarker, [&](const QString &marker) {
|
if (Utils::anyOf(commentMarker, [&](const QString &marker) {
|
||||||
return trimmedText.startsWith(marker);
|
return trimmedText.startsWith(marker);
|
||||||
})) {
|
})) {
|
||||||
|
if (Utils::anyOf(docMarker, [&](const QString &marker) {
|
||||||
|
return trimmedText.startsWith(marker)
|
||||||
|
&& (trimmedText.size() == marker.size()
|
||||||
|
|| trimmedText.at(marker.size()).isSpace());
|
||||||
|
})) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
TextDocumentLayout::doFoldOrUnfold(block, false);
|
TextDocumentLayout::doFoldOrUnfold(block, false);
|
||||||
moveCursorVisible();
|
moveCursorVisible();
|
||||||
documentLayout->requestUpdate();
|
documentLayout->requestUpdate();
|
||||||
|
Reference in New Issue
Block a user