From 20f1b74ce927e3d1d29a3bff8e67c1bfd3b63d3f Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Tue, 24 Apr 2018 17:13:05 +0200 Subject: [PATCH] Allow defining keyboard shortcuts for missing actions When users bind custom shortcuts to actions coming from extensions, the shortcuts can be loaded before the extensions, so we need to allow defining a shortcut for an action that doesn't exist yet. Closes gh-3549 Closes gh-2954 --- notebook/static/base/js/keyboard.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/notebook/static/base/js/keyboard.js b/notebook/static/base/js/keyboard.js index e07415ab3..531870fdd 100644 --- a/notebook/static/base/js/keyboard.js +++ b/notebook/static/base/js/keyboard.js @@ -454,7 +454,14 @@ define([ **/ var action_name = this.actions.get_name(data); if (! action_name){ - throw new Error('does not know how to deal with : ' + data); + if (typeof data === 'string') { + // If we have an action name, allow it to be bound anyway. + console.log("Unknown action '" + data + "' for shortcut " + shortcut + + "; it may be defined by an extension which is not yet loaded."); + action_name = data; + } else { + throw new Error('does not know how to deal with : ' + data); + } } var _shortcut = normalize_shortcut(shortcut); this.set_shortcut(_shortcut, action_name);