forked from qt-creator/qt-creator
CPP, QmlJs editors: don't indent when moving commented lines up/down.
Currently, pressing Ctrl + Shift + Up/Down with a commented block of
text selected will indent that block if the line two lines above the
block is indented. This is undesirable, because the indenting for that
block is incorrect when it is uncommented. See the following example:
Step 1:
void f()
{
int x;
// int y;
}
Step 2 - After Ctrl + Shift + Up:
void f()
{
int x;
// int y;
}
Step 3 - After uncommenting the block:
void f()
{
int x;
int y;
}
This patch tells the CPP and QmlJs editors not to indent commented
blocks when moving them. Blocks that are not entirely within comments
(excluding whitespace) are not affected.
Tested with (C++ and JavaScript, respectively):
http://paste.kde.org/688778/
http://paste.kde.org/688784/
Change-Id: I35414e6dfd5a1084fd997594e711ea9932231981
Reviewed-by: David Schulz <david.schulz@digia.com>
This commit is contained in:
@@ -70,6 +70,7 @@
|
||||
#include <utils/stylehelper.h>
|
||||
#include <utils/tooltip/tooltip.h>
|
||||
#include <utils/tooltip/tipcontents.h>
|
||||
#include <utils/uncommentselection.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QTextCodec>
|
||||
@@ -1171,7 +1172,28 @@ void BaseTextEditorWidget::moveLineUpDown(bool up)
|
||||
}
|
||||
d->m_refactorOverlay->setMarkers(nonAffectedMarkers + affectedMarkers);
|
||||
|
||||
reindent(document(), move);
|
||||
bool shouldReindent = true;
|
||||
const Utils::CommentDefinition* commentDefinition(editor()->commentDefinition());
|
||||
if (commentDefinition) {
|
||||
QString trimmedText(text.trimmed());
|
||||
|
||||
if (commentDefinition->hasSingleLineStyle()) {
|
||||
if (trimmedText.startsWith(commentDefinition->singleLine()))
|
||||
shouldReindent = false;
|
||||
}
|
||||
if (shouldReindent && commentDefinition->hasMultiLineStyle()) {
|
||||
// Don't have any single line comments; try multi line.
|
||||
if (trimmedText.startsWith(commentDefinition->multiLineStart())
|
||||
&& trimmedText.endsWith(commentDefinition->multiLineEnd())) {
|
||||
shouldReindent = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldReindent) {
|
||||
// The text was not commented at all; re-indent.
|
||||
reindent(document(), move);
|
||||
}
|
||||
move.endEditBlock();
|
||||
|
||||
setTextCursor(move);
|
||||
@@ -6347,6 +6369,11 @@ void BaseTextEditor::select(int toPos)
|
||||
e->setTextCursor(tc);
|
||||
}
|
||||
|
||||
const CommentDefinition *BaseTextEditor::commentDefinition() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BaseTextEditor::updateCursorPosition()
|
||||
{
|
||||
const QTextCursor cursor = e->textCursor();
|
||||
|
||||
Reference in New Issue
Block a user