From 9ef62848ac042fce4f38e1e0779c249c42f600ad Mon Sep 17 00:00:00 2001
From: mae <qtc-committer@nokia.com>
Date: Fri, 5 Dec 2008 17:06:17 +0100
Subject: [PATCH] avoid parentheses matching flicker when navigationt to block
 end / start.

---
 src/plugins/texteditor/basetexteditor.cpp | 29 ++++++++++++++++++-----
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index 49d29b75c93..82a4201b264 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -602,29 +602,44 @@ void BaseTextEditor::slotSelectionChanged()
 void BaseTextEditor::gotoBlockStart()
 {
     QTextCursor cursor = textCursor();
-    if (TextBlockUserData::findPreviousOpenParenthesis(&cursor, false))
+    if (TextBlockUserData::findPreviousOpenParenthesis(&cursor, false)) {
         setTextCursor(cursor);
+        _q_matchParentheses();
+    }
 }
 
 void BaseTextEditor::gotoBlockEnd()
 {
     QTextCursor cursor = textCursor();
-    if (TextBlockUserData::findNextClosingParenthesis(&cursor, false))
+    if (TextBlockUserData::findNextClosingParenthesis(&cursor, false)) {
         setTextCursor(cursor);
+        _q_matchParentheses();
+    }
 }
 
 void BaseTextEditor::gotoBlockStartWithSelection()
 {
     QTextCursor cursor = textCursor();
-    if (TextBlockUserData::findPreviousOpenParenthesis(&cursor, true))
+    if (TextBlockUserData::findPreviousOpenParenthesis(&cursor, true)) {
         setTextCursor(cursor);
+        _q_matchParentheses();
+    }
 }
 
 void BaseTextEditor::gotoBlockEndWithSelection()
 {
     QTextCursor cursor = textCursor();
-    if (TextBlockUserData::findNextClosingParenthesis(&cursor, true))
+    if (TextBlockUserData::findNextClosingParenthesis(&cursor, true)) {
         setTextCursor(cursor);
+        _q_matchParentheses();
+    }
+}
+
+static QTextCursor flippedCursor(const QTextCursor &cursor) {
+    QTextCursor flipped = cursor;
+    flipped.clearSelection();
+    flipped.setPosition(cursor.anchor(), QTextCursor::KeepAnchor);
+    return flipped;
 }
 
 void BaseTextEditor::selectBlockUp()
@@ -640,7 +655,8 @@ void BaseTextEditor::selectBlockUp()
         return;
     if (!TextBlockUserData::findNextClosingParenthesis(&cursor, true))
         return;
-    setTextCursor(cursor);
+    setTextCursor(flippedCursor(cursor));
+    _q_matchParentheses();
 }
 
 void BaseTextEditor::selectBlockDown()
@@ -663,7 +679,8 @@ void BaseTextEditor::selectBlockDown()
     if ( cursor != d->m_selectBlockAnchor)
         TextBlockUserData::findNextClosingParenthesis(&cursor, true);
 
-    setTextCursor(cursor);
+    setTextCursor(flippedCursor(cursor));
+    _q_matchParentheses();
 }
 
 
-- 
GitLab