Commit 3446e003 authored by Eike Ziller's avatar Eike Ziller

TextEditor: Fix tab indentation if single line is selected

If single line was indented with tab, and the insertion point was at the
beginning of the line, the selection moved away from the beginning of
the line. Pressing tab a second time then deletes the line, because the
line is no longer completely selected.

This behavior was also not consistent to the case where the insertion
point is not at the beginning of the line.
The patch makes sure that the selection stays at the beginning of the

Task-number: QTCREATORBUG-8421
Change-Id: I9847c2fe41e2e4f993f5e486c071acc112adb45d
Reviewed-by: default avatarDavid Schulz <>
parent 35a16cc3
......@@ -126,7 +126,8 @@ QTextCursor TextDocumentPrivate::indentOrUnindent(const QTextCursor &textCursor,
QTextBlock startBlock = m_document.findBlock(start);
QTextBlock endBlock = m_document.findBlock(blockSelection ? end : end - 1).next();
const bool cursorAtBlockStart = (textCursor.position() == startBlock.position());
const bool anchorAtBlockStart = (textCursor.anchor() == startBlock.position());
const bool oneLinePartial = ( == endBlock)
&& (start > startBlock.position() || end < endBlock.position() - 1);
......@@ -146,6 +147,17 @@ QTextCursor TextDocumentPrivate::indentOrUnindent(const QTextCursor &textCursor,
cursor.setPosition(block.position() + indentPosition, QTextCursor::KeepAnchor);
// make sure that selection that begins in first column stays at first column
// even if we insert text at first column
if (cursorAtBlockStart) {
cursor = textCursor;
cursor.setPosition(startBlock.position(), QTextCursor::KeepAnchor);
} else if (anchorAtBlockStart) {
cursor = textCursor;
cursor.setPosition(startBlock.position(), QTextCursor::MoveAnchor);
cursor.setPosition(textCursor.position(), QTextCursor::KeepAnchor);
} else {
modified = false;
} else if (cursor.hasSelection() && !blockSelection && oneLinePartial) {
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment