Repository: spyder-ide/spyder

Issue:
Autocomplete triggered by Ctrl + Enter
**Steps to reproduce:**
* Write a call to some function in the editor.
* Write something inside the function arguments.
* Position the focus to right before the closing parenthesis.
* Wait until some auto-complete suggestion comes up (or don't wait at all, they will show up anyway).
* Press Ctrl + Enter (shortcut to run a line).
```python
import numpy as np
y = np.random.random(size = 1000<focus here and press Ctrl + Enter>)
```
result:
```
y = np.random.random(size = 1000ArithmeticError)
```

**Expected behavior:** should run the line (Ctrl + Enter having precedence over raw Enter).

**Actual behavior:** triggers autocomplete, and doesn't run line.


Discussion:
The default shortcut for to run a line is `F9`. `Ctrl+Enter is for running the current cell. You can remap the keybind for these shortcuts in the settings if you want.

![image](https://user-images.githubusercontent.com/10170372/70737260-1fccf800-1ce0-11ea-8536-07a6098fdba7.png)

The auto-complete showing after a number is related to https://github.com/spyder-ide/spyder/issues/10833
Yes, working on a fix for that now.!
> Press Ctrl + Enter (shortcut to run a line).

Lines don't run anymore with Ctrl+Enter, so you need to remap that shortcut as @jnsebgosselin pointed out.
I remapped the shortcut, but the issue still persists (Ctrl + Enter triggers autocomplete).
Ok, thanks for the clarification. @goanpeca said he's working on this right now.
I can confirm this. It's not the shortcut but the the fact that only enter should except the completeion and not shift or ctrl(or alt, cmd, super, meta?) + enter should except the completion.

Should this issue it be reopened? 
>I can confirm this. It's not the shortcut but the the fact that only enter should except the completeion and not shift or ctrl(or alt, cmd, super, meta?) + enter should except the completion.

I do not understand what you meant, could you please rephrase?
> I do not understand what you meant, could you please rephrase?

Obviously not autocompleting on entering numbers, whitespaces or newlines fixes the original posters bug here(Great fix by the way!), but I don't think that ctrl+ enter (or shift, etc + enter) should accept completions at all. This is nice for people (like me) who work with code cells or for people who change short cuts and want ctrl+enter as inset a new line. Currently the completion overlay takes all of those key presses as accept the suggestion when it's active.

I hope this is more clear.
@andfoy, please don't forget to address this one next week.

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
@@ -1440,7 +1440,6 @@ def handle_folding_range(self, response):
              requires_response=False)
     def notify_save(self):
         """Send save request."""
-        # self.document_did_change()
         params = {'file': self.filename}
         if self.save_include_text:
             params['text'] = self.toPlainText()
@@ -1665,7 +1664,7 @@ def is_python_like(self):
         return self.is_python() or self.is_cython() or self.is_enaml()
 
     def intelligent_tab(self):
-        """Provide intelligent behavoir for Tab key press"""
+        """Provide intelligent behavior for Tab key press."""
         leading_text = self.get_text('sol', 'cursor')
         if not leading_text.strip() or leading_text.endswith('#'):
             # blank line or start of comment
@@ -3702,8 +3701,6 @@ def _start_completion_timer(self):
 
     def keyPressEvent(self, event):
         """Reimplement Qt method."""
-        self._start_completion_timer()
-
         tab_pressed = False
         if self.completions_hint_after_ms > 0:
             self._completions_hint_idle = False
@@ -3731,6 +3728,12 @@ def insert_text(event):
         if text:
             self.__clear_occurrences()
 
+            # Only ask for completions if there's some text generated
+            # as part of the event. Events such as pressing Crtl,
+            # Shift or Alt don't generate any text.
+            # Fixes spyder-ide/spyder#11021
+            self._start_completion_timer()
+
         if key in {Qt.Key_Up, Qt.Key_Left, Qt.Key_Right, Qt.Key_Down}:
             self.hide_tooltip()
 


Test patch:
diff --git a/spyder/utils/tests/test_encoding.py b/spyder/utils/tests/test_encoding.py
--- a/spyder/utils/tests/test_encoding.py
+++ b/spyder/utils/tests/test_encoding.py
@@ -70,6 +70,9 @@ def test_permissions(tmpdir):
     assert old_mode == new_mode
 
 
+@pytest.mark.skipif(
+    PY2,
+    reason="It fails with very small differences on Python 2")
 def test_timestamp(tmpdir):
     """Check that the modification timestamp is preserved."""
     tmp_file = tmpdir.mkdir("timestamp").join('test_file.txt')