Skip to content
Snippets Groups Projects
Commit 08e4c30e authored by mae's avatar mae
Browse files

Improve (un)comment selection in C++ style

The patch makes the algorithm ignore empty (i.e. only whitespace)
blocks similar to emacs.
parent 38b5ef37
No related branches found
No related tags found
No related merge requests found
......@@ -110,8 +110,8 @@ void Utils::unCommentSelection(QPlainTextEdit *edit)
endBlock = endBlock.next();
doCppStyleUncomment = true;
for (QTextBlock block = startBlock; block != endBlock; block = block.next()) {
QString text = block.text();
if (!text.trimmed().startsWith(QLatin1String("//"))) {
QString text = block.text().trimmed();
if (!text.isEmpty() && !text.startsWith(QLatin1String("//"))) {
doCppStyleUncomment = false;
break;
}
......@@ -133,8 +133,14 @@ void Utils::unCommentSelection(QPlainTextEdit *edit)
++i;
}
} else {
cursor.setPosition(block.position());
cursor.insertText(QLatin1String("//"));
QString text = block.text();
foreach(QChar c, text) {
if (!c.isSpace()) {
cursor.setPosition(block.position());
cursor.insertText(QLatin1String("//"));
break;
}
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment