KeyShortcutHandler return from functions after calling error handlers
This commit is contained in:
@@ -14,9 +14,9 @@
|
|||||||
`(whenLet [handler ,handler]
|
`(whenLet [handler ,handler]
|
||||||
(handler ,@args)))
|
(handler ,@args)))
|
||||||
|
|
||||||
(defMacro tryCallOrThrow [handler message &rest args]
|
(defMacro tryCallOrThrow [handler message returnNull &rest args]
|
||||||
`(ifLet [handler ,handler]
|
`(ifLet [handler ,handler]
|
||||||
(handler ,@args)
|
{(handler ,@args),(if (eval returnNull) `(return null) `(return))}
|
||||||
(throw ,message)))
|
(throw ,message)))
|
||||||
|
|
||||||
(method _selectMap [m]
|
(method _selectMap [m]
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
(rootMap.clear))
|
(rootMap.clear))
|
||||||
|
|
||||||
(method handleKey [:String key]
|
(method handleKey [:String key]
|
||||||
(unless currentMap (tryCallOrThrow onBadKey "Tried to handle key $key without calling start() first" key null))
|
(unless currentMap (tryCallOrThrow onBadKey "Tried to handle key $key without calling start() first" true key null))
|
||||||
(if (= cancelKey key)
|
(if (= cancelKey key)
|
||||||
(cancel)
|
(cancel)
|
||||||
(case (dictGet currentMap key)
|
(case (dictGet currentMap key)
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
((Prefix nextMap)
|
((Prefix nextMap)
|
||||||
(_selectMap nextMap))
|
(_selectMap nextMap))
|
||||||
(otherwise
|
(otherwise
|
||||||
(tryCallOrThrow onBadKey "Key $key is not defined in $currentMap and no onBadKey event was given" key currentMap)))))
|
(tryCallOrThrow onBadKey "Key $key is not defined in $currentMap and no onBadKey event was given" true key currentMap)))))
|
||||||
|
|
||||||
// Extract [k]eyboard [s]hortcuts from a string:
|
// Extract [k]eyboard [s]hortcuts from a string:
|
||||||
(method extractKeyboardShortcuts [str &opt :Stream stream :Array<String> shortcuts]
|
(method extractKeyboardShortcuts [str &opt :Stream stream :Array<String> shortcuts]
|
||||||
@@ -58,14 +58,14 @@
|
|||||||
((Some newShortcuts)
|
((Some newShortcuts)
|
||||||
(extractKeyboardShortcuts str stream (shortcuts.concat (newShortcuts.split ""))))
|
(extractKeyboardShortcuts str stream (shortcuts.concat (newShortcuts.split ""))))
|
||||||
(otherwise
|
(otherwise
|
||||||
(tryCallOrThrow onBadShortcut "unclosed [ in $str" str null)
|
(tryCallOrThrow onBadShortcut "unclosed [ in $str" true str null)
|
||||||
[])))
|
[])))
|
||||||
((Some "{")
|
((Some "{")
|
||||||
(case (stream.takeUntilAndDrop "}")
|
(case (stream.takeUntilAndDrop "}")
|
||||||
((Some newShortcut)
|
((Some newShortcut)
|
||||||
(extractKeyboardShortcuts str stream (shortcuts.concat [newShortcut])))
|
(extractKeyboardShortcuts str stream (shortcuts.concat [newShortcut])))
|
||||||
(otherwise
|
(otherwise
|
||||||
(tryCallOrThrow onBadShortcut "unclosed { in $str" str null)
|
(tryCallOrThrow onBadShortcut "unclosed { in $str" true str null)
|
||||||
[])))
|
[])))
|
||||||
(otherwise (throw "takeUntilOneOf lied"))))
|
(otherwise (throw "takeUntilOneOf lied"))))
|
||||||
(otherwise
|
(otherwise
|
||||||
@@ -81,11 +81,11 @@
|
|||||||
(if keys
|
(if keys
|
||||||
(case existingKey
|
(case existingKey
|
||||||
((Final _)
|
((Final _)
|
||||||
(tryCallOrThrow onBadShortcut conflictMessage description existingKey))
|
(tryCallOrThrow onBadShortcut conflictMessage false description existingKey))
|
||||||
((Prefix innerPrefixMap)
|
((Prefix innerPrefixMap)
|
||||||
(registerShortcut keys description item innerPrefixMap))
|
(registerShortcut keys description item innerPrefixMap))
|
||||||
(otherwise))
|
(otherwise))
|
||||||
(tryCallOrThrow onBadShortcut conflictMessage description existingKey))))
|
(tryCallOrThrow onBadShortcut conflictMessage false description existingKey))))
|
||||||
(true
|
(true
|
||||||
(if keys
|
(if keys
|
||||||
(let [innerPrefixMap (new Map)]
|
(let [innerPrefixMap (new Map)]
|
||||||
|
Reference in New Issue
Block a user