From aeb27e751eda9b58ba573111b0aa932fd3505e08 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 14 Sep 2022 19:35:30 +0000 Subject: [PATCH] KeyShortcutHandler return from functions after calling error handlers --- .../src/kiss_tools/KeyShortcutHandler.kiss | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/projects/kiss-tools/src/kiss_tools/KeyShortcutHandler.kiss b/projects/kiss-tools/src/kiss_tools/KeyShortcutHandler.kiss index 189b4de6..23de02ff 100644 --- a/projects/kiss-tools/src/kiss_tools/KeyShortcutHandler.kiss +++ b/projects/kiss-tools/src/kiss_tools/KeyShortcutHandler.kiss @@ -14,9 +14,9 @@ `(whenLet [handler ,handler] (handler ,@args))) -(defMacro tryCallOrThrow [handler message &rest args] +(defMacro tryCallOrThrow [handler message returnNull &rest args] `(ifLet [handler ,handler] - (handler ,@args) + {(handler ,@args),(if (eval returnNull) `(return null) `(return))} (throw ,message))) (method _selectMap [m] @@ -34,7 +34,7 @@ (rootMap.clear)) (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) (cancel) (case (dictGet currentMap key) @@ -44,7 +44,7 @@ ((Prefix nextMap) (_selectMap nextMap)) (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: (method extractKeyboardShortcuts [str &opt :Stream stream :Array shortcuts] @@ -58,14 +58,14 @@ ((Some newShortcuts) (extractKeyboardShortcuts str stream (shortcuts.concat (newShortcuts.split "")))) (otherwise - (tryCallOrThrow onBadShortcut "unclosed [ in $str" str null) + (tryCallOrThrow onBadShortcut "unclosed [ in $str" true str null) []))) ((Some "{") (case (stream.takeUntilAndDrop "}") ((Some newShortcut) (extractKeyboardShortcuts str stream (shortcuts.concat [newShortcut]))) (otherwise - (tryCallOrThrow onBadShortcut "unclosed { in $str" str null) + (tryCallOrThrow onBadShortcut "unclosed { in $str" true str null) []))) (otherwise (throw "takeUntilOneOf lied")))) (otherwise @@ -81,11 +81,11 @@ (if keys (case existingKey ((Final _) - (tryCallOrThrow onBadShortcut conflictMessage description existingKey)) + (tryCallOrThrow onBadShortcut conflictMessage false description existingKey)) ((Prefix innerPrefixMap) (registerShortcut keys description item innerPrefixMap)) (otherwise)) - (tryCallOrThrow onBadShortcut conflictMessage description existingKey)))) + (tryCallOrThrow onBadShortcut conflictMessage false description existingKey)))) (true (if keys (let [innerPrefixMap (new Map)]