forked from qt-creator/qt-creator
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:
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user