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 <marcus.tillmanns@qt.io>
This commit is contained in:
David Schulz
2023-10-13 11:38:05 +02:00
parent c53c9b539e
commit 8608cc2a13

View File

@@ -151,12 +151,16 @@ MultiTextCursor TextDocumentPrivate::indentOrUnindent(const MultiTextCursor &cur
} }
} }
} else { } else {
QString text = startBlock.text(); const QString text = startBlock.text();
int indentPosition = tabSettings.positionAtColumn(text, column, nullptr, true); int indentPosition = tabSettings.positionAtColumn(text, column, nullptr, true);
int spaces = tabSettings.spacesLeftFromPosition(text, indentPosition); int spaces = TabSettings::spacesLeftFromPosition(text, indentPosition);
int startColumn = tabSettings.columnAt(text, indentPosition - spaces); if (!doIndent && spaces == 0) {
int targetColumn = tabSettings.indentedColumn(tabSettings.columnAt(text, indentPosition), indentPosition = tabSettings.firstNonSpace(text);
doIndent); 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);
cursor.setPosition(startBlock.position() + indentPosition - spaces, cursor.setPosition(startBlock.position() + indentPosition - spaces,
QTextCursor::KeepAnchor); QTextCursor::KeepAnchor);