From d81d41032abc4b6f0fa1971fa8a594c669da2f48 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Mon, 20 Nov 2023 08:14:32 +0100 Subject: [PATCH] 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 Reviewed-by: --- src/plugins/texteditor/texteditor.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index db85a570178..e59bc993fca 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -1919,6 +1919,7 @@ void TextEditorWidgetPrivate::foldLicenseHeader() if (TextDocumentLayout::canFold(block) && block.next().isVisible()) { const QString trimmedText = text.trimmed(); QStringList commentMarker; + QStringList docMarker; if (auto highlighter = qobject_cast( q->textDocument()->syntaxHighlighter())) { const Highlighter::Definition def = highlighter->definition(); @@ -1929,11 +1930,19 @@ void TextEditorWidgetPrivate::foldLicenseHeader() } } else { commentMarker = QStringList({"/*", "#"}); + docMarker = QStringList({"/*!", "/**"}); } if (Utils::anyOf(commentMarker, [&](const QString &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); moveCursorVisible(); documentLayout->requestUpdate();