From 78f130a121e40c01f8b5c13d8451bd3aeba039ad Mon Sep 17 00:00:00 2001 From: mae <qt-info@nokia.com> Date: Mon, 17 May 2010 10:36:59 +0200 Subject: [PATCH] Fix Backtab behavior to standard Windows behavior Creator implemented Backtab similar to Eclipse and other editors, now we do standard windows behavior. --- src/plugins/texteditor/basetexteditor.cpp | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 2598bd69e62..61e50d3f7b1 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -3651,19 +3651,7 @@ void BaseTextEditor::indentOrUnindent(bool doIndent) QTextDocument *doc = document(); - 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());; - int spaces = tabSettings.spacesLeftFromPosition(text, indentPosition); - int startColumn = tabSettings.columnAt(text, indentPosition - spaces); - int targetColumn = tabSettings.indentedColumn(tabSettings.columnAt(text, indentPosition), doIndent); - cursor.setPosition(block.position() + indentPosition); - cursor.setPosition(block.position() + indentPosition - spaces, QTextCursor::KeepAnchor); - cursor.removeSelectedText(); - cursor.insertText(tabSettings.indentationString(startColumn, targetColumn, block)); - } else { + if (cursor.hasSelection()) { // Indent or unindent the selected lines int anchor = cursor.anchor(); int start = qMin(anchor, pos); @@ -3684,6 +3672,18 @@ void BaseTextEditor::indentOrUnindent(bool doIndent) cursor.setPosition(block.position() + indentPosition, QTextCursor::KeepAnchor); cursor.removeSelectedText(); } + } else { + // Indent or unindent at cursor position + QTextBlock block = cursor.block(); + QString text = block.text(); + int indentPosition = cursor.positionInBlock(); + int spaces = tabSettings.spacesLeftFromPosition(text, indentPosition); + int startColumn = tabSettings.columnAt(text, indentPosition - spaces); + int targetColumn = tabSettings.indentedColumn(tabSettings.columnAt(text, indentPosition), doIndent); + cursor.setPosition(block.position() + indentPosition); + cursor.setPosition(block.position() + indentPosition - spaces, QTextCursor::KeepAnchor); + cursor.removeSelectedText(); + cursor.insertText(tabSettings.indentationString(startColumn, targetColumn, block)); } cursor.endEditBlock(); -- GitLab