forked from qt-creator/qt-creator
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 line. Task-number: QTCREATORBUG-8421 Change-Id: I9847c2fe41e2e4f993f5e486c071acc112adb45d Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
@@ -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 = (startBlock.next() == endBlock)
|
||||
&& (start > startBlock.position() || end < endBlock.position() - 1);
|
||||
|
||||
@@ -146,6 +147,17 @@ QTextCursor TextDocumentPrivate::indentOrUnindent(const QTextCursor &textCursor,
|
||||
cursor.setPosition(block.position());
|
||||
cursor.setPosition(block.position() + indentPosition, QTextCursor::KeepAnchor);
|
||||
cursor.removeSelectedText();
|
||||
}
|
||||
// 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) {
|
||||
|
||||
Reference in New Issue
Block a user