From fdc246397130b73457237feaa01dfdb3b099a152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Mon, 7 Dec 2009 16:43:11 +0100 Subject: [PATCH] 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 --- src/plugins/texteditor/basetexteditor.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 8f51ed65745..b9bcb9660df 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -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);