KeyShortcutHandler allow special keys

This commit is contained in:
2022-08-20 21:51:11 +00:00
parent 3583113613
commit 213720e330

View File

@@ -47,17 +47,27 @@
(tryCallOrThrow onBadKey "Key $key is not defined in $currentMap and no onBadKey event was given" key currentMap)))))
// Extract [k]eyboard [s]hortcuts from a string:
(method extractKeyboardShortcuts [str &opt :Stream stream :String shortcuts]
(method extractKeyboardShortcuts [str &opt :Stream stream :Array<String> shortcuts]
(unless stream (set stream (Stream.fromString str)))
(unless shortcuts (set shortcuts ""))
(case (stream.takeUntilAndDrop "[")
(unless shortcuts (set shortcuts []))
(case (stream.takeUntilOneOf ["[" "{"] false)
((Some _)
(case (stream.takeUntilAndDrop "]")
((Some newShortcuts)
(extractKeyboardShortcuts str stream (+ shortcuts newShortcuts)))
(otherwise
(tryCallOrThrow onBadShortcut "unclosed [ in $str" str null)
"")))
(case (stream.takeChars 1)
((Some "[")
(case (stream.takeUntilAndDrop "]")
((Some newShortcuts)
(extractKeyboardShortcuts str stream (shortcuts.concat (newShortcuts.split ""))))
(otherwise
(tryCallOrThrow onBadShortcut "unclosed [ in $str" str null)
[])))
((Some "{")
(case (stream.takeUntilAndDrop "}")
((Some newShortcut)
(extractKeyboardShortcuts str stream (shortcuts.concat [newShortcut])))
(otherwise
(tryCallOrThrow onBadShortcut "unclosed { in $str" str null)
[])))
(otherwise (throw "takeUntilOneOf lied"))))
(otherwise
shortcuts)))
@@ -85,4 +95,4 @@
(method :Void registerItem [description :T item]
(whenLet [keyboardShortcut (extractKeyboardShortcuts description)]
(registerShortcut (keyboardShortcut.split "") description item)))
(registerShortcut keyboardShortcut description item)))