From 8608cc2a13a215732079a137dd8385beea82c00b Mon Sep 17 00:00:00 2001 From: David Schulz Date: Fri, 13 Oct 2023 11:38:05 +0200 Subject: [PATCH] TextEditor: improve unindent If there are no spaces in front of the text cursor unindent the whole line. Fixes: QTCREATORBUG-29742 Change-Id: I7daaf1670c1378e6b40b959ef7114c87ffe4115c Reviewed-by: Marcus Tillmanns --- src/plugins/texteditor/textdocument.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp index ddc25d2a276..3556a08caa0 100644 --- a/src/plugins/texteditor/textdocument.cpp +++ b/src/plugins/texteditor/textdocument.cpp @@ -151,12 +151,16 @@ MultiTextCursor TextDocumentPrivate::indentOrUnindent(const MultiTextCursor &cur } } } else { - QString text = startBlock.text(); + const QString text = startBlock.text(); int indentPosition = tabSettings.positionAtColumn(text, column, nullptr, true); - int spaces = tabSettings.spacesLeftFromPosition(text, indentPosition); - int startColumn = tabSettings.columnAt(text, indentPosition - spaces); - int targetColumn = tabSettings.indentedColumn(tabSettings.columnAt(text, indentPosition), - doIndent); + int spaces = TabSettings::spacesLeftFromPosition(text, indentPosition); + if (!doIndent && spaces == 0) { + indentPosition = tabSettings.firstNonSpace(text); + spaces = TabSettings::spacesLeftFromPosition(text, indentPosition); + } + const int startColumn = tabSettings.columnAt(text, indentPosition - spaces); + const int targetColumn + = tabSettings.indentedColumn(tabSettings.columnAt(text, indentPosition), doIndent); cursor.setPosition(startBlock.position() + indentPosition); cursor.setPosition(startBlock.position() + indentPosition - spaces, QTextCursor::KeepAnchor);