From 3990bb109ae3fdd5332346221bfc955349bfe3f9 Mon Sep 17 00:00:00 2001 From: Tim Daniel Metzler Date: Fri, 15 Mar 2024 18:37:58 +0100 Subject: [PATCH] Use spread operator to remove shortcuts --- .../src/disable-shortcuts.js | 8 ++++++-- packages/utils/src/shortcuts.js | 12 ++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/restricted-exam-notebook/src/disable-shortcuts.js b/packages/restricted-exam-notebook/src/disable-shortcuts.js index 7bb49735..29eee897 100644 --- a/packages/restricted-exam-notebook/src/disable-shortcuts.js +++ b/packages/restricted-exam-notebook/src/disable-shortcuts.js @@ -18,12 +18,16 @@ export function disable_shortcuts() { "d,d", ]; - utils.remove_shortcuts("command", shortcuts); - utils.remove_shortcuts("edit", shortcuts); + const modes = ["command", "edit"]; + + for (let mode of modes) { + utils.remove_shortcuts(mode, ...shortcuts); + } utils.remove_shortcuts("command", "crtl-v"); utils.disable_add_cell_on_execute(); + utils.add_shortcut( "command", "ctrl-v", diff --git a/packages/utils/src/shortcuts.js b/packages/utils/src/shortcuts.js index b8a360c3..8a1b5843 100644 --- a/packages/utils/src/shortcuts.js +++ b/packages/utils/src/shortcuts.js @@ -53,6 +53,14 @@ export function remove_shortcuts(mode, ...shortcuts) { try { manager.remove_shortcut(shortcut); } catch (e) { + console.log( + "Error removing shortcut", + shortcut, + "from", + mode, + "mode:", + e.message + ); // Shortcut does not exist and can't be removed; } } @@ -83,8 +91,8 @@ export function add_shortcut(mode, key, handler, help, help_index = "zz") { export function disable_add_cell_on_execute() { add_Notebook_execute_cell_and_select(); const shortcut_keys = ["alt-enter", "shift-enter"]; - remove_shortcuts("edit", shortcut_keys); - remove_shortcuts("command", shortcut_keys); + remove_shortcuts("edit", ...shortcut_keys); + remove_shortcuts("command", ...shortcut_keys); const help = "run cell"; const handler = function (event) {