aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/hotkey-handler.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-17 17:05:06 -0500
committerGitHub <noreply@github.com>2021-01-17 17:05:06 -0500
commit04d53e5642ddf4fe9a15f22df0c3892e53074739 (patch)
tree573f1b6028c24534bdb5c1502789cf236c7aeed5 /ext/mixed/js/hotkey-handler.js
parent14b4aee07dc3f69ad75518cf04cafe416e06f0c7 (diff)
Optimize hotkey registration (#1264)
Diffstat (limited to 'ext/mixed/js/hotkey-handler.js')
-rw-r--r--ext/mixed/js/hotkey-handler.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/ext/mixed/js/hotkey-handler.js b/ext/mixed/js/hotkey-handler.js
index 81ec950e..2de2a8d2 100644
--- a/ext/mixed/js/hotkey-handler.js
+++ b/ext/mixed/js/hotkey-handler.js
@@ -106,6 +106,23 @@ class HotkeyHandler extends EventDispatcher {
}
/**
+ * Assigns a set of hotkeys for a given scope. This is an optimized shorthand for calling
+ * `clearHotkeys`, then calling `registerHotkeys`.
+ * @see registerHotkeys for argument information.
+ */
+ setHotkeys(scope, hotkeys) {
+ let registrations = this._hotkeyRegistrations.get(scope);
+ if (typeof registrations === 'undefined') {
+ registrations = [];
+ this._hotkeyRegistrations.set(scope, registrations);
+ } else {
+ registrations.length = 0;
+ }
+ registrations.push(...hotkeys);
+ this._updateHotkeyRegistrations();
+ }
+
+ /**
* Adds a single event listener to a specific event.
* @param eventName The string representing the event's name.
* @param callback The event listener callback to add.