Repository: spyder-ide/spyder

Issue:
Unreasonably irritating autocomplete behavior
### 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)
* [ NA] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [ NA] 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 & Steps to Reproduce
CAVEAT: I realize this is a minor issue and it probably irritates me more than it should.  I also realize that I can use the esc key to avoid this problem.  Thanks for all the work you put into Spyder, it's a great tool.  

That said:
Autocomplete is annoyingly unhelpful when revising a line of code.  Say I need to add a function call around some existing code (i.e. =float(<existing code>), when I type "float(", the autocomplete popup appears.  When I hit "end" to try to add the closing paren, I end up at the end of the autocomplete popup instead of at the end of the line (see the screenshot).

![image](https://user-images.githubusercontent.com/32210294/200129914-f0c3a674-6988-41f4-8db8-919f538720ca.png)

### What is the expected output? What do you see instead?
Personally, I'd like to see the "end" key move the cursor to the end of the line of code instead of the end of the autocomplete popup

## Versions
* Spyder version: 5.3.2
* Python version: 3.9.12
* Operating System name/version: windows 11




Discussion:
Hey @jeremymatt, thanks for reporting. I think this is a good suggestion and (fortunately) not a difficult one to implement. We'll try to come up with a fix for it in our next version (5.4.1), to be released before the end of the year.

You also said

> Thanks for all the work you put into Spyder, it's a great tool.

Thanks for your kind words! We're really glad to know you find it useful for your work.
Fantastic to hear!  

Resolving patch:
diff --git a/spyder/plugins/editor/widgets/completion.py b/spyder/plugins/editor/widgets/completion.py
--- a/spyder/plugins/editor/widgets/completion.py
+++ b/spyder/plugins/editor/widgets/completion.py
@@ -339,8 +339,10 @@ def keyPressEvent(self, event):
         elif key in (Qt.Key_Left, Qt.Key_Right) or text in ('.', ':'):
             self.hide()
             self.textedit.keyPressEvent(event)
-        elif key in (Qt.Key_Up, Qt.Key_Down, Qt.Key_PageUp, Qt.Key_PageDown,
-                     Qt.Key_Home, Qt.Key_End) and not modifier:
+        elif (
+            key in (Qt.Key_Up, Qt.Key_Down, Qt.Key_PageUp, Qt.Key_PageDown)
+            and not modifier
+        ):
             self.textedit._completions_hint_idle = True
             if key == Qt.Key_Up and self.currentRow() == 0:
                 self.setCurrentRow(self.count() - 1)
@@ -348,6 +350,12 @@ def keyPressEvent(self, event):
                 self.setCurrentRow(0)
             else:
                 QListWidget.keyPressEvent(self, event)
+        elif key in (Qt.Key_Home, Qt.Key_End):
+            # This allows users to easily move to the beginning/end of the
+            # current line when this widget is visible.
+            # Fixes spyder-ide/spyder#19989
+            self.hide()
+            self.textedit.keyPressEvent(event)
         elif key == Qt.Key_Backspace:
             self.textedit.keyPressEvent(event)
             self.update_current(new=False)
@@ -377,6 +385,10 @@ def keyPressEvent(self, event):
                 if QKeySequence(key_sequence) == QKeySequence(save_shortcut):
                     self.textedit.sig_save_requested.emit()
 
+                    # Hiding the widget reassures users that the save operation
+                    # took place.
+                    self.hide()
+
             self.textedit.keyPressEvent(event)
             self.update_current(new=False)
         elif modifier:


Test patch:
diff --git a/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py b/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py
--- a/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py
+++ b/spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py
@@ -367,7 +367,7 @@ def test_banners(ipyconsole, qtbot):
     [("arange",
       ["start", "stop"],
       ["Return evenly spaced values within a given interval.<br>",
-       "<br>Python built-in `range` function, but returns an ndarray ..."]),
+       "open interval ..."]),
      ("vectorize",
       ["pyfunc", "otype", "signature"],
       ["Generalized function class.<br>",