From a328c19aba3de4011aea3798afe5ceff617f7956 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Wed, 26 Jan 2022 20:46:06 +0100 Subject: [PATCH] Backport PR #330: Add `Accel Enter` shortcut to execute a cell --- packages/notebook-extension/src/index.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/notebook-extension/src/index.ts b/packages/notebook-extension/src/index.ts index 5fc98186..474f79ac 100644 --- a/packages/notebook-extension/src/index.ts +++ b/packages/notebook-extension/src/index.ts @@ -223,6 +223,28 @@ const kernelStatus: JupyterFrontEndPlugin = { } }; +/** + * A plugin to add an extra shortcut to execute a cell in place via Cmd-Enter on Mac. + * TODO: switch to settings define menus when fixed upstream: https://github.com/jupyterlab/jupyterlab/issues/11754 + */ +const runShortcut: JupyterFrontEndPlugin = { + id: '@retrolab/notebook-extension:run-shortcut', + autoStart: true, + activate: (app: JupyterFrontEnd) => { + app.commands.addKeyBinding({ + command: 'notebook:run-cell', + keys: ['Accel Enter'], + selector: '.jp-Notebook:focus' + }); + + app.commands.addKeyBinding({ + command: 'notebook:run-cell', + keys: ['Accel Enter'], + selector: '.jp-Notebook.jp-mod-editMode' + }); + } +}; + /** * A plugin to enable scrolling for outputs by default. * Mimic the logic from the classic notebook, as found here: @@ -319,6 +341,7 @@ const plugins: JupyterFrontEndPlugin[] = [ checkpoints, kernelLogo, kernelStatus, + runShortcut, scrollOutput ];