From 609e3c7f6b9496e6e3de8355037b108c1fec66ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com>
Date: Wed, 15 Jul 2009 16:10:15 +0200
Subject: [PATCH] Update the current line highlight when its color might have
 changed

Fixes the issue where it would stay the color of the previous color
scheme until you change the cursor position.
---
 src/plugins/texteditor/basetexteditor.cpp | 34 +++++++++++++----------
 src/plugins/texteditor/basetexteditor.h   |  1 +
 2 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index 63507ae1637..414e5c7bb26 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -1245,7 +1245,7 @@ bool BaseTextEditor::isParenthesesMatchingEnabled() const
 void BaseTextEditor::setHighlightCurrentLine(bool b)
 {
     d->m_highlightCurrentLine = b;
-    slotCursorPositionChanged();
+    updateCurrentLineHighlight();
 }
 
 bool BaseTextEditor::highlightCurrentLine() const
@@ -2582,6 +2582,22 @@ void BaseTextEditor::saveCurrentCursorPositionForNavigation()
     d->m_tempNavigationState = saveState();
 }
 
+void BaseTextEditor::updateCurrentLineHighlight()
+{
+    QList<QTextEdit::ExtraSelection> extraSelections;
+
+    if (d->m_highlightCurrentLine) {
+        QTextEdit::ExtraSelection sel;
+        sel.format.setBackground(d->m_currentLineFormat.background());
+        sel.format.setProperty(QTextFormat::FullWidthSelection, true);
+        sel.cursor = textCursor();
+        sel.cursor.clearSelection();
+        extraSelections.append(sel);
+    }
+
+    setExtraSelections(CurrentLineSelection, extraSelections);
+}
+
 void BaseTextEditor::slotCursorPositionChanged()
 {
     if (!d->m_contentsChanged && d->m_lastCursorChangeWasInteresting) {
@@ -2602,18 +2618,7 @@ void BaseTextEditor::slotCursorPositionChanged()
         }
     }
 
-    QList<QTextEdit::ExtraSelection> extraSelections;
-
-    if (d->m_highlightCurrentLine) {
-        QTextEdit::ExtraSelection sel;
-        sel.format.setBackground(d->m_currentLineFormat.background());
-        sel.format.setProperty(QTextFormat::FullWidthSelection, true);
-        sel.cursor = textCursor();
-        sel.cursor.clearSelection();
-        extraSelections.append(sel);
-    }
-
-    setExtraSelections(CurrentLineSelection, extraSelections);
+    updateCurrentLineHighlight();
 
     if (d->m_displaySettings.m_highlightBlocks) {
         QTextCursor cursor = textCursor();
@@ -3898,7 +3903,8 @@ void BaseTextEditor::setFontSettings(const TextEditor::FontSettings &fs)
     d->m_matchFormat.setForeground(parenthesesFormat.foreground());
     d->m_rangeFormat.setBackground(parenthesesFormat.background());
 
-    slotUpdateExtraAreaWidth();
+    slotUpdateExtraAreaWidth();   // Adjust to new font width
+    updateCurrentLineHighlight(); // Make sure it takes the new color
 }
 
 void BaseTextEditor::setTabSettings(const TabSettings &ts)
diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h
index 9dd92405791..5bcf962ed9e 100644
--- a/src/plugins/texteditor/basetexteditor.h
+++ b/src/plugins/texteditor/basetexteditor.h
@@ -526,6 +526,7 @@ private:
     void moveLineUpDown(bool up);
     void copyLineUpDown(bool up);
     void saveCurrentCursorPositionForNavigation();
+    void updateCurrentLineHighlight();
 
     void drawFoldingMarker(QPainter *painter, const QPalette &pal,
                            const QRect &rect,
-- 
GitLab