Repository: spyder-ide/spyder

Issue:
Hover tips interfere with editor text selection
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [X] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [X] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [X] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [ ] Tried basic troubleshooting (if a bug/error)
    * [ ] Restarted Spyder
    * [ ] Reset preferences with ``spyder --reset``
    * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [ ] Tried the other applicable steps from the Troubleshooting Guide
* [X] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description

The hover hints interfere with highlighting text.

![hover_and _drag](https://user-images.githubusercontent.com/10513354/69575406-66ec8680-0f87-11ea-9cbd-ffc88b045033.gif)

![hover_and _drag_up](https://user-images.githubusercontent.com/10513354/69575408-67851d00-0f87-11ea-844e-2ac30e36a0b0.gif)


### What steps reproduce the problem?

1. Activate a hover
2. Click and drag to highlight
3. Can't see the highlighting

### What is the expected output? What do you see instead?

I think that if the hover windows disapapere if the user clicks in the editor that would be one way to solve it

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: master
* Python version: 3.7.3 64-bit
* Qt version: Qt 5.9.6
* PyQt version: PyQt5 5.9.2
* Operating System name/version: Linux

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
PASTE DEPENDENCIES HERE
```
cloudpickle >=0.5.0          :  1.2.1 (OK)
pygments >=2.0               :  2.4.2 (OK)
qtconsole >=4.6.0            :  4.6.0 (OK)
nbconvert >=4.0              :  5.5.0 (OK)
sphinx >=0.6.6               :  2.1.2 (OK)
pylint >=0.25                :  2.3.1 (OK)
psutil >=0.3                 :  5.6.3 (OK)
qtawesome >=0.5.7            :  0.5.7 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
zmq >=17                     :  18.1.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
numpydoc >=0.6.0             :  0.9.1 (OK)
spyder_kernels >=1.8.0;<2.0.0:  1.9.0.dev0 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
atomicwrites >=1.2.0         :  1.3.0 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
watchdog                     :  None (OK)
keyring                      :  None (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pympler                      :  None (OK)
sympy >=0.7.3                :  1.4 (OK)
cython >=0.21                :  0.29.13 (OK)
IPython >=4.0                :  7.9.0 (OK)
matplotlib >=2.0.0           :  3.1.0 (OK)
pandas >=0.13.1              :  0.25.0 (OK)
numpy >=1.7                  :  1.17.3 (OK)
scipy >=0.17.0               :  1.3.1 (OK)
pyls >=0.31.0;<0.32.0        :  0.31.1 (OK)
xdg >=0.26                   :  0.26 (OK)
rtree >=0.8.3                :  0.8.3 (OK)


Discussion:
I also have this issue. 

Another problem is that hover tips crash on 4.0.0rc2+MacOS 10.11.6. The crash does not affect Spyder, only hover tip itself.
> Another problem is that hover tips crash on 4.0.0rc2+MacOS 10.11.6. The crash does not affect Spyder, only hover tip itself.

@liuyigh please write a separate issue for this with an error traceback and a reproducible code example so we can keep track of the error.
#10852 issue submitted. Thanks!
@goanpeca, what do you think we could do about this one?
>I think that if the hover windows disapapere if the user clicks in the editor that would be one way to solve it

I agree that the hover should probably disappear on any key press. This should be a very easy fix.
@goanpeca I forgot to mention that the hover is also activated while the mouse button is held down as well. See my second gif.

Would it be possible to disable hovers tips while the mouse button is depressed as well?
>Would it be possible to disable hovers tips while the mouse button is depressed as well?

Absolutely! that is a silly UX :-p this one is probably on me 😆 

Resolving patch:
diff --git a/spyder/plugins/editor/widgets/codeeditor.py b/spyder/plugins/editor/widgets/codeeditor.py
--- a/spyder/plugins/editor/widgets/codeeditor.py
+++ b/spyder/plugins/editor/widgets/codeeditor.py
@@ -535,6 +535,7 @@ def __init__(self, parent=None):
         # Mouse tracking
         self.setMouseTracking(True)
         self.__cursor_changed = False
+        self._mouse_left_button_pressed = False
         self.ctrl_click_color = QColor(Qt.blue)
 
         self.bookmarks = self.get_bookmarks()
@@ -610,7 +611,9 @@ def __init__(self, parent=None):
     # --- Hover/Hints
     def _should_display_hover(self, point):
         """Check if a hover hint should be displayed:"""
-        return self.hover_hints_enabled and point and self.get_word_at(point)
+        if not self._mouse_left_button_pressed:
+            return (self.hover_hints_enabled and point
+                    and self.get_word_at(point))
 
     def _handle_hover(self):
         """Handle hover hint trigger after delay."""
@@ -2292,9 +2295,11 @@ def hide_tooltip(self):
         when the user leaves the Linenumber area when hovering over lint
         warnings and errors.
         """
+        self._timer_mouse_moving.stop()
         self._last_hover_word = None
-        self.tooltip_widget.hide()
         self.clear_extra_selections('code_analysis_highlight')
+        if self.tooltip_widget.isVisible():
+            self.tooltip_widget.hide()
 
     def _set_completions_hint_idle(self):
         self._completions_hint_idle = True
@@ -3645,6 +3650,10 @@ def insert_text(event):
 
         if text:
             self.__clear_occurrences()
+
+        if key in {Qt.Key_Up, Qt.Key_Left, Qt.Key_Right, Qt.Key_Down}:
+            self.hide_tooltip()
+
         if QToolTip.isVisible():
             self.hide_tooltip_if_necessary(key)
 
@@ -3996,6 +4005,7 @@ def go_to_uri_from_cursor(self, uri):
         """Go to url from cursor and defined hover patterns."""
         key = self._last_hover_pattern_key
         full_uri = uri
+
         if key in ['file']:
             fname = self._preprocess_file_uri(uri)
 
@@ -4047,6 +4057,7 @@ def go_to_uri_from_cursor(self, uri):
                     QMessageBox.Ok,
                 )
         self.sig_go_to_uri.emit(uri)
+        self.hide_tooltip()
         return full_uri
 
     def line_range(self, position):
@@ -4207,11 +4218,14 @@ def leaveEvent(self, event):
 
     def mousePressEvent(self, event):
         """Override Qt method."""
+        self.hide_tooltip()
         self.kite_call_to_action.handle_mouse_press(event)
 
         ctrl = event.modifiers() & Qt.ControlModifier
         alt = event.modifiers() & Qt.AltModifier
         pos = event.pos()
+        self._mouse_left_button_pressed = event.button() == Qt.LeftButton
+
         if event.button() == Qt.LeftButton and ctrl:
             TextEditBaseWidget.mousePressEvent(self, event)
             cursor = self.cursorForPosition(pos)
@@ -4227,6 +4241,9 @@ def mousePressEvent(self, event):
 
     def mouseReleaseEvent(self, event):
         """Override Qt method."""
+        if event.button() == Qt.LeftButton:
+            self._mouse_left_button_pressed = False
+
         self.request_cursor_event()
         TextEditBaseWidget.mouseReleaseEvent(self, event)
 
@@ -4449,6 +4466,7 @@ def load(self, filename):
                                               osp.dirname(filename)))
         oe_proxy = OutlineExplorerProxyEditor(self.editor, filename)
         self.classtree.set_current_editor(oe_proxy, False, False)
+        self.hide_tooltip()
 
 
 def test(fname):


Test patch: