KeyShortcutHandler detect conflict with cancelKey
This commit is contained in:
@@ -12,6 +12,7 @@ typedef BadKeyHandler<T> = (String, PrefixMap<T>) -> Void;
|
|||||||
typedef BadShortcutHandler<T> = (String, ShortcutKey<T>) -> Void;
|
typedef BadShortcutHandler<T> = (String, ShortcutKey<T>) -> Void;
|
||||||
|
|
||||||
enum ShortcutKey<T> {
|
enum ShortcutKey<T> {
|
||||||
|
Cancel(key:String);
|
||||||
Final(item:T);
|
Final(item:T);
|
||||||
Prefix(keys:PrefixMap<T>);
|
Prefix(keys:PrefixMap<T>);
|
||||||
}
|
}
|
||||||
|
@@ -75,12 +75,12 @@
|
|||||||
(unless prefixMap (set prefixMap rootMap))
|
(unless prefixMap (set prefixMap rootMap))
|
||||||
(let [firstKey (keys.shift)]
|
(let [firstKey (keys.shift)]
|
||||||
(cond
|
(cond
|
||||||
((prefixMap.exists firstKey)
|
((or (prefixMap.exists firstKey) (= firstKey cancelKey))
|
||||||
(let [existingKey (dictGet prefixMap firstKey)
|
(let [existingKey (if (= firstKey cancelKey) (Cancel cancelKey) (dictGet prefixMap firstKey))
|
||||||
conflictMessage "Keyboard shortcut for $description conflicts with $existingKey"]
|
conflictMessage "Keyboard shortcut for $description conflicts with $existingKey"]
|
||||||
(if keys
|
(if keys
|
||||||
(case existingKey
|
(case existingKey
|
||||||
((Final _)
|
((or (Final _) (Cancel _))
|
||||||
(tryCallOrThrow onBadShortcut conflictMessage false description existingKey))
|
(tryCallOrThrow onBadShortcut conflictMessage false description existingKey))
|
||||||
((Prefix innerPrefixMap)
|
((Prefix innerPrefixMap)
|
||||||
(registerShortcut keys description item innerPrefixMap))
|
(registerShortcut keys description item innerPrefixMap))
|
||||||
|
Reference in New Issue
Block a user