Repository: spyder-ide/spyder

Issue:
Cursor is not restore properly in the Editor
## Problem Description

The cursor in the Editor is not restored properly after it was changed to a `PointingHandCursor`.

![cursor](https://user-images.githubusercontent.com/10170372/58898648-0875d800-86c9-11e9-91ac-c222742f8e11.gif)

### What steps reproduce the problem?

1. Select a word or a url in the Editor
2.  Press `Ctrl + F` or `Ctrl + C` or `Ctrl + R`  combination
3.  Move the mouse around

Also

1. Go over a word with the mouse cursor
2.  Press `Ctrl`
3.  Release `Ctrl`

### What is the expected output? What do you see instead?

The cursor remains to `Qt.PointingHandCursor` while it should be restored with `restoreOverrideCursor`

## Versions

* Spyder version: Spyder 4.0.0.dev0 (Commit: 64a9d6ad9) 
* Python version: Python 3.7.1 64-bit
* Qt version: Qt 5.9.6
* PyQt version: PyQt5 5.9.2
* Operating System name/version: Windows 10 



Discussion:
@ccordoba12 I'll take care of this, I know how to fix it.
Ok, thanks a lot @jnsebgosselin!
@jnsebgosselin we probably need to add the cursor restore here

https://github.com/spyder-ide/spyder/blob/master/spyder/plugins/editor/widgets/codeeditor.py#L3118

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
@@ -3119,8 +3119,7 @@ def keyReleaseEvent(self, event):
         """Override Qt method."""
         self.sig_key_released.emit(event)
         self.timer_syntax_highlight.start()
-        self.clear_extra_selections('ctrl_click')
-        self._last_hover_uri = None
+        self._restore_editor_cursor_and_selections()
         super(CodeEditor, self).keyReleaseEvent(event)
         event.ignore()
 
@@ -3539,9 +3538,7 @@ def mouseMoveEvent(self, event):
                 return
 
         if self.__cursor_changed:
-            QApplication.restoreOverrideCursor()
-            self.__cursor_changed = False
-            self.clear_extra_selections('ctrl_click')
+            self._restore_editor_cursor_and_selections()
         else:
             if not self._should_display_hover(pos):
                 self.hide_tooltip()
@@ -3561,18 +3558,15 @@ def setPlainText(self, txt):
         self.new_text_set.emit()
 
     def focusOutEvent(self, event):
-        """Reimplement Qt method"""
+        """Extend Qt method"""
         self.sig_focus_changed.emit()
+        self._restore_editor_cursor_and_selections()
         super(CodeEditor, self).focusOutEvent(event)
 
     def leaveEvent(self, event):
-        """If cursor has not been restored yet, do it now"""
+        """Extend Qt method"""
         self.sig_leave_out.emit()
-        if self.__cursor_changed:
-            QApplication.restoreOverrideCursor()
-            self.__cursor_changed = False
-            self.clear_extra_selections('ctrl_click')
-            self._last_hover_uri = None
+        self._restore_editor_cursor_and_selections()
         TextEditBaseWidget.leaveEvent(self, event)
 
     def mousePressEvent(self, event):
@@ -3669,6 +3663,14 @@ def contextMenuEvent(self, event):
         menu.popup(event.globalPos())
         event.accept()
 
+    def _restore_editor_cursor_and_selections(self):
+        """Restore the cursor and extra selections of this code editor."""
+        if self.__cursor_changed:
+            self.__cursor_changed = False
+            QApplication.restoreOverrideCursor()
+            self.clear_extra_selections('ctrl_click')
+            self._last_hover_uri = None
+
     #------ Drag and drop
     def dragEnterEvent(self, event):
         """Reimplement Qt method


Test patch: