Improve (un)comment selection in C++ style

The patch makes the algorithm ignore empty (i.e. only whitespace)
blocks similar to emacs.
This commit is contained in:
mae
2010-03-26 14:28:26 +01:00
parent 38b5ef374e
commit 08e4c30eb1

View File

@@ -110,8 +110,8 @@ void Utils::unCommentSelection(QPlainTextEdit *edit)
endBlock = endBlock.next(); endBlock = endBlock.next();
doCppStyleUncomment = true; doCppStyleUncomment = true;
for (QTextBlock block = startBlock; block != endBlock; block = block.next()) { for (QTextBlock block = startBlock; block != endBlock; block = block.next()) {
QString text = block.text(); QString text = block.text().trimmed();
if (!text.trimmed().startsWith(QLatin1String("//"))) { if (!text.isEmpty() && !text.startsWith(QLatin1String("//"))) {
doCppStyleUncomment = false; doCppStyleUncomment = false;
break; break;
} }
@@ -133,8 +133,14 @@ void Utils::unCommentSelection(QPlainTextEdit *edit)
++i; ++i;
} }
} else { } else {
QString text = block.text();
foreach(QChar c, text) {
if (!c.isSpace()) {
cursor.setPosition(block.position()); cursor.setPosition(block.position());
cursor.insertText(QLatin1String("//")); cursor.insertText(QLatin1String("//"));
break;
}
}
} }
} }
} }