Skip to content

Commit

Permalink
Use spread operator to remove shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
tmetzl committed Mar 15, 2024
1 parent e3877fc commit 3990bb1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 6 additions & 2 deletions packages/restricted-exam-notebook/src/disable-shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 10 additions & 2 deletions packages/utils/src/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3990bb1

Please sign in to comment.