From d8be1fbca48182a808e4a48a97a954b1a677430d Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Fri, 16 Apr 2010 13:25:44 +0200
Subject: [PATCH] textedit: make whitespace visualization work with overwrite
 mode cursor

Done with mae.
---
 src/plugins/texteditor/basetexteditor.cpp | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index 827ae6ad1d9..a01d5f2a818 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -2681,18 +2681,15 @@ void BaseTextEditor::paintEvent(QPaintEvent *e)
             bool drawCursorAsBlock = drawCursor && overwriteMode() ;
 
             if (drawCursorAsBlock) {
-                QTextLayout::FormatRange o;
                 int relativePos = context.cursorPosition - blpos;
-                o.start = relativePos;
-                o.length = 1;
-                o.format.setForeground(palette().base());
-                selections.append(o);
+                bool doSelection = true;
                 QTextLine line = layout->lineForTextPosition(relativePos);
                 qreal x = line.cursorToX(relativePos);
                 qreal w = 0;
                 if (relativePos < line.textLength() - line.textStart()) {
                     w = line.cursorToX(relativePos + 1) - x;
                     if (doc->characterAt(context.cursorPosition) == QLatin1Char('\t')) {
+                        doSelection = false;
                         int space = QFontMetrics(layout->font()).width(QLatin1Char(' '));
                         if (w > space) {
                             x += w-space;
@@ -2707,6 +2704,13 @@ void BaseTextEditor::paintEvent(QPaintEvent *e)
                 rr.moveLeft(r.left() + x);
                 rr.setWidth(w);
                 painter.fillRect(rr, palette().text());
+                if (doSelection) {
+                    QTextLayout::FormatRange o;
+                    o.start = relativePos;
+                    o.length = 1;
+                    o.format.setForeground(palette().base());
+                    selections.append(o);
+                }
             }
 
 
-- 
GitLab