From 473e998160f73872ad3dc8e76e96f96d9d369aea Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 14 Sep 2022 20:11:02 +0000 Subject: [PATCH] KeyShortcutHandler detect conflict with cancelKey --- projects/kiss-tools/src/kiss_tools/KeyShortcutHandler.hx | 1 + projects/kiss-tools/src/kiss_tools/KeyShortcutHandler.kiss | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/projects/kiss-tools/src/kiss_tools/KeyShortcutHandler.hx b/projects/kiss-tools/src/kiss_tools/KeyShortcutHandler.hx index 2bf8cdbe..5c3803d7 100644 --- a/projects/kiss-tools/src/kiss_tools/KeyShortcutHandler.hx +++ b/projects/kiss-tools/src/kiss_tools/KeyShortcutHandler.hx @@ -12,6 +12,7 @@ typedef BadKeyHandler = (String, PrefixMap) -> Void; typedef BadShortcutHandler = (String, ShortcutKey) -> Void; enum ShortcutKey { + Cancel(key:String); Final(item:T); Prefix(keys:PrefixMap); } diff --git a/projects/kiss-tools/src/kiss_tools/KeyShortcutHandler.kiss b/projects/kiss-tools/src/kiss_tools/KeyShortcutHandler.kiss index 23de02ff..39d8dbc2 100644 --- a/projects/kiss-tools/src/kiss_tools/KeyShortcutHandler.kiss +++ b/projects/kiss-tools/src/kiss_tools/KeyShortcutHandler.kiss @@ -75,12 +75,12 @@ (unless prefixMap (set prefixMap rootMap)) (let [firstKey (keys.shift)] (cond - ((prefixMap.exists firstKey) - (let [existingKey (dictGet prefixMap firstKey) + ((or (prefixMap.exists firstKey) (= firstKey cancelKey)) + (let [existingKey (if (= firstKey cancelKey) (Cancel cancelKey) (dictGet prefixMap firstKey)) conflictMessage "Keyboard shortcut for $description conflicts with $existingKey"] (if keys (case existingKey - ((Final _) + ((or (Final _) (Cancel _)) (tryCallOrThrow onBadShortcut conflictMessage false description existingKey)) ((Prefix innerPrefixMap) (registerShortcut keys description item innerPrefixMap))