TextEditor: Add option to prefer single line comments

Fixes: QTCREATORBUG-24017
Change-Id: Icf34710707b51ea9fbd348dd207950cffeedfdd3
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Jacopo Martellini
2021-02-04 10:59:05 +01:00
parent 8a243aa6ca
commit cc89f72fe5
7 changed files with 69 additions and 43 deletions

View File

@@ -74,7 +74,8 @@ static bool isComment(const QString &text, int index,
}
void Utils::unCommentSelection(QPlainTextEdit *edit, const CommentDefinition &definition)
void Utils::unCommentSelection(QPlainTextEdit *edit, const CommentDefinition &definition,
bool preferSingleLine)
{
if (!definition.isValid())
return;
@@ -103,7 +104,7 @@ void Utils::unCommentSelection(QPlainTextEdit *edit, const CommentDefinition &de
bool hasSelection = cursor.hasSelection();
if (hasSelection && definition.hasMultiLineStyle()) {
if (hasSelection && definition.hasMultiLineStyle() && !preferSingleLine) {
QString startText = startBlock.text();
int startPos = start - startBlock.position();
@@ -145,6 +146,7 @@ void Utils::unCommentSelection(QPlainTextEdit *edit, const CommentDefinition &de
} else if (!hasSelection && !definition.hasSingleLineStyle()) {
QString text = startBlock.text().trimmed();
doMultiLineStyleUncomment = text.startsWith(definition.multiLineStart)
&& text.endsWith(definition.multiLineEnd);
doMultiLineStyleComment = !doMultiLineStyleUncomment && !text.isEmpty();