From 01a4864762bcf5c64cd40671a628783122cbea50 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 15 Mar 2022 13:49:58 -0700 Subject: [PATCH] Add hotkeys.register_help, forward the event to the hotkey's func. --- .../etiquette_flask/static/js/hotkeys.js | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/frontends/etiquette_flask/static/js/hotkeys.js b/frontends/etiquette_flask/static/js/hotkeys.js index daa6442..3882cdf 100644 --- a/frontends/etiquette_flask/static/js/hotkeys.js +++ b/frontends/etiquette_flask/static/js/hotkeys.js @@ -1,6 +1,7 @@ const hotkeys = {}; hotkeys.HOTKEYS = {}; +hotkeys.HELPS = []; hotkeys.hotkey_identifier = function hotkey_identifier(key, ctrlKey, shiftKey, altKey) @@ -14,14 +15,20 @@ function hotkey_human(key, ctrlKey, shiftKey, altKey) { // Return the string that will be displayed to the user to represent this hotkey. let mods = []; - if (ctrlKey) { mods.push("Ctrl"); } - if (shiftKey) { mods.push("Shift"); } - if (altKey) { mods.push("Alt"); } + if (ctrlKey) { mods.push("CTRL"); } + if (shiftKey) { mods.push("SHIFT"); } + if (altKey) { mods.push("ALT"); } mods = mods.join("+"); if (mods) { mods = mods + "+"; } return mods + key.toUpperCase(); } +hotkeys.register_help = +function register_help(help) +{ + hotkeys.HELPS.push(help); +} + hotkeys.register_hotkey = function register_hotkey(hotkey, action, description) { @@ -68,6 +75,14 @@ function show_all_hotkeys() const line = hotkeys.HOTKEYS[identifier]["human"] + " : " + hotkeys.HOTKEYS[identifier]["description"]; lines.push(line); } + if (hotkeys.HELPS) + { + lines.push(""); + } + for (const help of hotkeys.HELPS) + { + lines.push(help); + } lines = lines.join("\n"); alert(lines); } @@ -75,6 +90,7 @@ function show_all_hotkeys() hotkeys.hotkeys_listener = function hotkeys_listener(event) { + // console.log(event.key); if (hotkeys.should_prevent_hotkey(event)) { return; @@ -84,7 +100,7 @@ function hotkeys_listener(event) //console.log(identifier); if (identifier in hotkeys.HOTKEYS) { - hotkeys.HOTKEYS[identifier]["action"](); + hotkeys.HOTKEYS[identifier]["action"](event); event.preventDefault(); } }