KeyShortcutHandler detect conflict with cancelKey

This commit is contained in:
2022-09-14 20:11:02 +00:00
parent df7b898806
commit 7beb6cf689
2 changed files with 4 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ typedef BadKeyHandler<T> = (String, PrefixMap<T>) -> Void;
typedef BadShortcutHandler<T> = (String, ShortcutKey<T>) -> Void;
enum ShortcutKey<T> {
Cancel(key:String);
Final(item:T);
Prefix(keys:PrefixMap<T>);
}

View File

@@ -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))