From 63d18a45377cac0d6f2f4f66cd5facb4817aace9 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Tue, 14 Nov 2017 15:31:59 +0100 Subject: [PATCH] Editor: Fix indenting on the very first position of a document Task-number: QTCREATORBUG-19294 Change-Id: I3c859d90f0c58165d526b2c9dd9a7afe2abda94b Reviewed-by: Christian Stenger --- src/plugins/texteditor/textdocument.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp index 9e8befb9391..f843b28d0ca 100644 --- a/src/plugins/texteditor/textdocument.cpp +++ b/src/plugins/texteditor/textdocument.cpp @@ -128,7 +128,7 @@ QTextCursor TextDocumentPrivate::indentOrUnindent(const QTextCursor &textCursor, bool modified = true; QTextBlock startBlock = m_document.findBlock(start); - QTextBlock endBlock = m_document.findBlock(blockSelection ? end : end - 1).next(); + QTextBlock endBlock = m_document.findBlock(blockSelection ? end : qMax(end - 1, 0)).next(); const bool cursorAtBlockStart = (textCursor.position() == startBlock.position()); const bool anchorAtBlockStart = (textCursor.anchor() == startBlock.position()); const bool oneLinePartial = (startBlock.next() == endBlock)