From db5f2f1411806d6b6d9984576a4fa8efa0a75b08 Mon Sep 17 00:00:00 2001
From: Eike Ziller <eike.ziller@digia.com>
Date: Fri, 30 May 2014 15:26:13 +0200
Subject: [PATCH] Text editors: Do not show tool tip for empty area

The editors were showing tool tips for the last cursor position in a
line, even if the mouse was hovered over the empty space behind the
line.

Task-number: QTCREATORBUG-9437
Change-Id: Ibe3b0140b73c3a15811eeaf50a15d75f378f37f4
Reviewed-by: David Schulz <david.schulz@digia.com>
---
 src/plugins/texteditor/basetexteditor.cpp | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index 4cbb8c2a848..998db4545a6 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -2517,8 +2517,17 @@ bool BaseTextEditorWidget::viewportEvent(QEvent *event)
             return true;
         }
 
-        processTooltipRequest(cursorForPosition(pos));
-        return true;
+        QTextCursor tc = cursorForPosition(pos);
+        QTextBlock block = tc.block();
+        QTextLine line = block.layout()->lineForTextPosition(tc.positionInBlock());
+        QTC_CHECK(line.isValid());
+        // Only handle tool tip for text cursor if mouse is within the block for the text cursor,
+        // and not if the mouse is e.g. in the empty space behind a short line.
+        if (line.isValid()
+                && pos.x() <= blockBoundingGeometry(block).left() + line.naturalTextRect().right()) {
+            processTooltipRequest(tc);
+            return true;
+        }
     }
     return QPlainTextEdit::viewportEvent(event);
 }
-- 
GitLab