From 13d11e7761cefae61af0d29a54e0e7513419ed63 Mon Sep 17 00:00:00 2001 From: Maksim Karelov Date: Fri, 6 Jan 2023 04:57:06 +0600 Subject: [PATCH 1/3] fix: shortcuts with `Option` key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related to #11. `event.key` returns transformed char when `option` key is pressed. For example, when user is trying to record shortcut `Option+Shift+G`, `event.key` returns `Option+Shift+˝`. `event.code` returns `KeyG` instead. So getting substring with offset 3 fixes this issue. This commit fixes another bug: when user records shortcut that already registered, window will hide. Adding `unregister` before start recording fixes this issue. --- src/routes/Settings/lib/controls/ShortcutControl.svelte | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/routes/Settings/lib/controls/ShortcutControl.svelte b/src/routes/Settings/lib/controls/ShortcutControl.svelte index 61e6255..fbf2e22 100644 --- a/src/routes/Settings/lib/controls/ShortcutControl.svelte +++ b/src/routes/Settings/lib/controls/ShortcutControl.svelte @@ -35,6 +35,8 @@ async function recordShortcut() { shortcutArray = []; hotkeys.unbind(); + // Prevent closing Preferences when recording already registered shortcut + unregister(preferences.get("shortcut")); hotkeys("*", { keyup: true }, function (event) { if (event.type === "keydown") { if (shortcutArray.length < 3) { @@ -52,7 +54,7 @@ if (event.key === " "){ shortcutArray.push("Space"); } else { - shortcutArray.push(event.key); + shortcutArray.push(event.code.substring(3)); } updateShortcutPreference(shortcutArray); hotkeys.unbind(); From 1fc13d4404814b88e436ead40e31dbbf00792fc8 Mon Sep 17 00:00:00 2001 From: Maksim Karelov Date: Fri, 6 Jan 2023 21:33:34 +0600 Subject: [PATCH 2/3] fix: properly resolve `Space` key --- src/routes/Settings/lib/controls/ShortcutControl.svelte | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/routes/Settings/lib/controls/ShortcutControl.svelte b/src/routes/Settings/lib/controls/ShortcutControl.svelte index fbf2e22..2fba893 100644 --- a/src/routes/Settings/lib/controls/ShortcutControl.svelte +++ b/src/routes/Settings/lib/controls/ShortcutControl.svelte @@ -51,11 +51,10 @@ } } else { if (!modifiers.includes(event.key)) { - if (event.key === " "){ - shortcutArray.push("Space"); - } else { - shortcutArray.push(event.code.substring(3)); - } + const key = event.code.startsWith("Key") + ? event.code.substring(3) + : event.code; + shortcutArray.push(key); updateShortcutPreference(shortcutArray); hotkeys.unbind(); } else { From e4daa95a001ceab2944ebecbe780cf831f2befd5 Mon Sep 17 00:00:00 2001 From: Maksim Karelov Date: Fri, 6 Jan 2023 22:48:20 +0600 Subject: [PATCH 3/3] fix: drop `unregister` code to fix it in another PR --- src/routes/Settings/lib/controls/ShortcutControl.svelte | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/routes/Settings/lib/controls/ShortcutControl.svelte b/src/routes/Settings/lib/controls/ShortcutControl.svelte index 2fba893..4bdfa56 100644 --- a/src/routes/Settings/lib/controls/ShortcutControl.svelte +++ b/src/routes/Settings/lib/controls/ShortcutControl.svelte @@ -35,8 +35,6 @@ async function recordShortcut() { shortcutArray = []; hotkeys.unbind(); - // Prevent closing Preferences when recording already registered shortcut - unregister(preferences.get("shortcut")); hotkeys("*", { keyup: true }, function (event) { if (event.type === "keydown") { if (shortcutArray.length < 3) {