vatlab / sos-notebook

Multi-language Jupyter Notebook
http://vatlab.github.io/SoS
BSD 3-Clause "New" or "Revised" License
176 stars 17 forks source link

Scratchpad shortcut independent from keyboard shortcut #277

Closed John-Drake closed 4 years ago

John-Drake commented 4 years ago

The scratchpad shortcut (Ctrl-Shift-Enter) maps to the "execute selected" shortcut within the keyboard menu. But if one changes that shortcut, the scratchpad is unresponsive to the new shortcut (but still responsive to Ctrl-Shift-Enter).

Is there a way to change the default shortcut for scratchpad?

BoPeng commented 4 years ago

Could you be more specific about what "scratchpad" is? Were you referring to the scratchpad extension?

John-Drake commented 4 years ago

Sorry for the confusion.

No, I am referring to the "scratch cell", which automatically shows up after installing SoS. This is is labeled as the "console" within my installation (The SoS presentation shows it as a "scratch tab", so I am assuming earlier versions called it scratch tab and newer versions call it a console. https://youtu.be/U75eKosFbp8?t=970)

BoPeng commented 4 years ago

I see. The "console" was motivated from the scratch pad extension and was named "scratch cell", but it was revised to follow a "console" UI since SoS Notebook uses JupyterLab's console for the same purpose.

The C-S-Enter shortcut is hard-coded since shortcut customization is a pretty recent feature of Jupyter. I will look into it and honor shortcuts specified by the shortcut manager.

BoPeng commented 4 years ago

OK, since Jupyter 5.0.0, there is

Jupyter.notebook.config.data.keys.command.bind

that points to something like

{
`new-short-cut`: "auto:execute-selected"
}

We simply need to honor the preference here.

BoPeng commented 4 years ago

OK, I see the problem. execute-selected is an editing shortcut that is triggered when you are editing a cell, not a command shortcut (after you press Escape). The shortcut edit dialog explicitly says it works only for command shortcuts, not for edit shortcuts, and setting shortcuts there for executed-selected has no effect.

BoPeng commented 4 years ago

I have renamed the action to sos:run-in-console to be consistent with JupyterLab. I have tried to add a shortcut manually in .jupyter/nbconfig/notebook.json

{
  "keys": {
    "edit": {
      "bind": {
        "ctrl-shift-g": "sos:run-in-console"
      }
    }
  }
}

but it does not work. I guess customizing edit-mode shortcuts is not supported at this point.