forked from qt-creator/qt-creator
Relax the selection requirement for indent/unindent selection
Before, the selection was required to span multiple lines. Now, any selection will trigger the line indenting functionality of Tab/Shift+Tab. This should lead to less surprises. Also, Shift+Tab will now always unindent the current line, even if there is no selection, since there is nothing else sensible for this shortcut to do. Task-number: QTCREATORBUG-414 Reviewed-by: mae
This commit is contained in:
@@ -3243,11 +3243,10 @@ void BaseTextEditor::indentOrUnindent(bool doIndent)
|
||||
int pos = cursor.position();
|
||||
const TextEditor::TabSettings &tabSettings = d->m_document->tabSettings();
|
||||
|
||||
|
||||
QTextDocument *doc = document();
|
||||
if (!cursor.hasSelection()
|
||||
|| (doc->findBlock(cursor.selectionStart()) == doc->findBlock(cursor.selectionEnd()) )) {
|
||||
cursor.removeSelectedText();
|
||||
|
||||
if (!cursor.hasSelection() && doIndent) {
|
||||
// Insert tab if there is no selection and indent is requested
|
||||
QTextBlock block = cursor.block();
|
||||
QString text = block.text();
|
||||
int indentPosition = (cursor.position() - block.position());;
|
||||
@@ -3260,6 +3259,7 @@ void BaseTextEditor::indentOrUnindent(bool doIndent)
|
||||
cursor.removeSelectedText();
|
||||
cursor.insertText(tabSettings.indentationString(startColumn, targetColumn));
|
||||
} else {
|
||||
// Indent or unindent the selected lines
|
||||
int anchor = cursor.anchor();
|
||||
int start = qMin(anchor, pos);
|
||||
int end = qMax(anchor, pos);
|
||||
|
Reference in New Issue
Block a user