From b9e376f5dd81c732df377fd108aea3ba23be90dd Mon Sep 17 00:00:00 2001
From: mae <qt-info@nokia.com>
Date: Fri, 24 Apr 2009 18:08:22 +0200
Subject: [PATCH] fix block highlighting off-by-one

---
 src/plugins/texteditor/basetexteditor.cpp | 10 ++++++----
 src/plugins/texteditor/basetexteditor.h   |  2 +-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index 5c3d084e211..9bc9ef529a6 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -3165,10 +3165,10 @@ bool TextBlockUserData::findPreviousOpenParenthesis(QTextCursor *cursor, bool se
     return false;
 }
 
-bool TextBlockUserData::findPreviousBlockOpenParenthesis(QTextCursor *cursor)
+bool TextBlockUserData::findPreviousBlockOpenParenthesis(QTextCursor *cursor, bool checkStartPosition)
 {
     QTextBlock block = cursor->block();
-    int position = cursor->position();
+    int position = cursor->position() + (checkStartPosition ? 1 : 0 );
     int ignore = 0;
     while (block.isValid()) {
         Parentheses parenList = TextEditDocumentLayout::parentheses(block);
@@ -3399,10 +3399,12 @@ void BaseTextEditor::_q_highlightBlocks()
         if (block.isValid()) {
             QTextCursor cursor(block);
             if (d->extraAreaHighlightCollapseColumn >= 0)
-                cursor.setPosition(cursor.position() + qMin(d->extraAreaHighlightCollapseColumn+1,
+                cursor.setPosition(cursor.position() + qMin(d->extraAreaHighlightCollapseColumn,
                                                             block.length()));
             QTextCursor closeCursor;
-            while (TextBlockUserData::findPreviousBlockOpenParenthesis(&cursor)) {
+            bool firstRun = true;
+            while (TextBlockUserData::findPreviousBlockOpenParenthesis(&cursor), firstRun) {
+                firstRun = false;
                 highlightBlocksInfo.open.prepend(cursor.blockNumber());
                 highlightBlocksInfo.visualIndent.prepend(d->visualIndent(cursor.block()));
                 if (closeCursor.isNull())
diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h
index 7493fd34c89..e917696b57e 100644
--- a/src/plugins/texteditor/basetexteditor.h
+++ b/src/plugins/texteditor/basetexteditor.h
@@ -167,7 +167,7 @@ public:
     static bool findPreviousOpenParenthesis(QTextCursor *cursor, bool select = false);
     static bool findNextClosingParenthesis(QTextCursor *cursor, bool select = false);
 
-    static bool findPreviousBlockOpenParenthesis(QTextCursor *cursor);
+    static bool findPreviousBlockOpenParenthesis(QTextCursor *cursor, bool checkStartPosition = false);
     static bool findNextBlockClosingParenthesis(QTextCursor *cursor);
 
 
-- 
GitLab