Repository: spyder-ide/spyder

Issue:
Cell shortcut remap not sticking on macOS
<!--- **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

* [ ] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [ ] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [ ] 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
* [ ] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description

When I remap Shift+Enter to run selection, and apply the changes, it does nothing when I press Shift+Enter rather than either run the selection or run all the code.

spyder: 4.0.1
spyder-kernel: 1.8.1
Operating System: OSX Catalina 10.15.3 (19D76)
PyQt5: 5.12.3

### What steps reproduce the problem?

1.  Remap run select to Shift+Enter from f9 on OSX
2. Try to run a code snippet using Shift+Enter

### What is the expected output? What do you see instead?

I expect it to run selection; instead it does nothing

### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback

PASTE TRACEBACK HERE

```

## 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: 
* Python version: 
* Qt version: 
* PyQt version: 
* Operating System name/version: 

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
PASTE DEPENDENCIES HERE
```



Discussion:
I can reproduce this. If I make the changes with spyder running and try to use it I get an Qt message on the Internal  console

(QAction ambiguous shortcut or similar I forgot)

If I restart it works as expected.

Please take a look at this @steff456 
I cannot reproduce on Windows on latest master.
But it seems an issue on 4.x (i didnot check master)
> 
> 
> But it seems an issue on 4.x (i didnot check master)

On latest 4.x I cannot reproduce also.
Same Qt version? (Maybe it is an OSX issue)

@impact27 could you test if you can reproduce?
> 
> Same Qt version? (Maybe it is an OSX issue)
> 
> @impact27 could you test if you can reproduce?

No, I run Spyder on Python 3.7.3 64-bit | Qt 5.9.6 | PyQt5 5.9.2 | Windows 10

PyQt 5.12.* is not available in Anaconda, so I cannot test under that version of PyQt easily unfortunately.
> @impact27 could you test if you can reproduce?

I can reproduce, I can't run selection from a keyboard shortcut.

Futhermore, the internal console prints when I try to use the shortcut: 

`QAction::event: Ambiguous shortcut overload: ??`

And if I change to maj + R:
`QAction::event: Ambiguous shortcut overload: ?R`


* Spyder version: 5.0.0.dev0 67c105d83
* Python version: 3.7.5
* Qt version: 5.12.6
* PyQt5 version: 5.12.3
* Operating System: Darwin 19.2.0
>No, I run Spyder on Python 3.7.3 64-bit | Qt 5.9.6 | PyQt5 5.9.2 | Windows 10
>PyQt 5.12.* is not available in Anaconda, so I cannot test under that version of PyQt easily unfortunately.

@jnsebgosselin you could use conda forge

`conda create --name spyder-test spyder=4 --channel conda-forge`
So the problem occurs no matter the shortcut you are using for `Run selection`?
Possible solution to this problem would be to set the context of the run actions to `Qt.WidgetWithChildrenShortcut` here :

https://github.com/spyder-ide/spyder/blob/47726b4d3d297b4bfbe6351905b6c44ef2b71e93/spyder/plugins/editor/widgets/codeeditor.py#L3581-L3603

Also, I think that the `run_cell_action`, `run_cell_advance_action` and `debug_cell_action` actions should be registered with `register_shortcut` here, because they are currently not updated during runtime, only after a restart :

https://github.com/spyder-ide/spyder/blob/47726b4d3d297b4bfbe6351905b6c44ef2b71e93/spyder/plugins/editor/plugin.py#L612-L638




@steff456 please fix this with @jnsebgosselin suggestions
> 
> 
> @steff456 please fix this with @jnsebgosselin suggestions

Since I can't test it, I don't know if this is going to fix the issue here. I'm just proposing stuff to try... :P
> 
> 
> > No, I run Spyder on Python 3.7.3 64-bit | Qt 5.9.6 | PyQt5 5.9.2 | Windows 10
> > PyQt 5.12.* is not available in Anaconda, so I cannot test under that version of PyQt easily unfortunately.
> 
> @jnsebgosselin you could use conda forge
> 
> `conda create --name spyder-test spyder=4 --channel conda-forge`

Thanks!
> Also, I think that the `run_cell_action`, `run_cell_advance_action` and `debug_cell_action` actions should be registered with `register_shortcut` here, because they are currently not updated during runtime, only after a restart :

The shortcut indeed works after a restart
> Since I can't test it, I don't know if this is going to fix the issue here. I'm just proposing stuff to try... :P

Thanks @jnsebgosselin! It worked perfectly :)

Resolving patch:
diff --git a/spyder/plugins/editor/plugin.py b/spyder/plugins/editor/plugin.py
--- a/spyder/plugins/editor/plugin.py
+++ b/spyder/plugins/editor/plugin.py
@@ -612,31 +612,39 @@ def get_plugin_actions(self):
         run_cell_action = create_action(self,
                             _("Run cell"),
                             icon=ima.icon('run_cell'),
-                            shortcut=CONF.get_shortcut('editor', 'run cell'),
                             tip=_("Run current cell \n"
                                   "[Use #%% to create cells]"),
                             triggered=self.run_cell,
                             context=Qt.WidgetShortcut)
 
+        self.register_shortcut(run_cell_action, context="Editor",
+                               name="Run cell", add_shortcut_to_tip=True)
+
         run_cell_advance_action = create_action(
             self,
             _("Run cell and advance"),
             icon=ima.icon('run_cell_advance'),
-            shortcut=CONF.get_shortcut('editor', 'run cell and advance'),
             tip=_("Run current cell and go to the next one "),
             triggered=self.run_cell_and_advance,
             context=Qt.WidgetShortcut)
 
+        self.register_shortcut(run_cell_advance_action, context="Editor",
+                               name="Run cell and advance",
+                               add_shortcut_to_tip=True)
+
         self.debug_cell_action = create_action(
             self,
             _("Debug cell"),
             icon=ima.icon('debug_cell'),
-            shortcut=CONF.get_shortcut('editor', 'debug cell'),
             tip=_("Debug current cell "
                   "(Alt+Shift+Enter)"),
             triggered=self.debug_cell,
             context=Qt.WidgetShortcut)
 
+        self.register_shortcut(self.debug_cell_action, context="Editor",
+                               name="Debug cell",
+                               add_shortcut_to_tip=True)
+
         re_run_last_cell_action = create_action(self,
                    _("Re-run last cell"),
                    tip=_("Re run last cell "),


Test patch: