From d832e2d4165f454bccb57efb6a171473282a1fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20K=C3=B6nig?= Date: Thu, 24 Nov 2022 13:21:09 +0100 Subject: [PATCH] unbind hotkeys with scope to allow unbinding hotkeys only within a scope if one has been provided (see also #177) --- src/use-hotkeys/use-hotkeys.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/use-hotkeys/use-hotkeys.ts b/src/use-hotkeys/use-hotkeys.ts index dfedba3c..e1864870 100644 --- a/src/use-hotkeys/use-hotkeys.ts +++ b/src/use-hotkeys/use-hotkeys.ts @@ -49,8 +49,10 @@ export class UseHotkeys extends StimulusUse { } unbind = () => { - for (const hotkey in this.hotkeysOptions.hotkeys as any) { - hotkeys.unbind(hotkey) + for (const [hotkey, definition] of Object.entries(this.hotkeysOptions.hotkeys as any)) { + const options = (definition as HotkeyDefinition).options + const scope = options.scope ? options.scope : '' + hotkeys.unbind(hotkey, scope) } }