Pass KeyShortcutHandler consumers a printable prefixmap represention. Close #154.
This commit is contained in:
@@ -5,7 +5,7 @@ import kiss.Stream;
|
||||
import kiss.List;
|
||||
|
||||
typedef PrefixMap<T> = Map<String, ShortcutKey<T>>;
|
||||
typedef PrefixMapHandler<T> = (Map<String, ShortcutKey<T>>) -> Void;
|
||||
typedef PrefixMapHandler<T> = (Map<String, ShortcutKey<T>>, Map<String,String>) -> Void;
|
||||
typedef ItemHandler<T> = (T) -> Void;
|
||||
typedef FinishHandler = () -> Void;
|
||||
typedef BadKeyHandler<T> = (String, PrefixMap<T>) -> Void;
|
||||
|
@@ -21,7 +21,7 @@
|
||||
|
||||
(method _selectMap [m]
|
||||
(set currentMap m)
|
||||
(tryCall onSelectPrefixMap m))
|
||||
(tryCall onSelectPrefixMap m (prefixMapToStrings m)))
|
||||
|
||||
(method start []
|
||||
(_selectMap rootMap))
|
||||
@@ -99,4 +99,12 @@
|
||||
|
||||
(method :Void registerItem [description :T item]
|
||||
(whenLet [keyboardShortcut (extractKeyboardShortcuts description)]
|
||||
(registerShortcut keyboardShortcut description item)))
|
||||
(registerShortcut keyboardShortcut description item)))
|
||||
|
||||
(method :Map<String,String> prefixMapToStrings [:PrefixMap<T> map]
|
||||
(for =>key mapping map
|
||||
=>key (case mapping
|
||||
((Cancel _) "cancel")
|
||||
((Final thing) (Std.string thing))
|
||||
((Prefix map) (.join (collect (map.keys)) ", "))
|
||||
(never null))))
|
@@ -93,7 +93,7 @@
|
||||
(_runCommand command selectedTextBeforeShortcut))
|
||||
(_runCommand command selectedTextBeforeShortcut)))
|
||||
|
||||
(function :Void showShortcutPanel [:PrefixMap<String> prefixMap]
|
||||
(function :Void showShortcutPanel [:PrefixMap<String> prefixMap :Map<String,String> strings]
|
||||
// Preserve the selected text and focused document before opening the webview:
|
||||
(whenLet [text (selectedText)] (set selectedTextBeforeShortcut text))
|
||||
(when activeTextEditor
|
||||
@@ -109,20 +109,15 @@
|
||||
(set keyListener
|
||||
(shortcutPanel.webview.onDidReceiveMessage
|
||||
->:Void key (shortcutHandler.handleKey (the String key))))
|
||||
(set shortcutPanel.webview.html (shortcutPanelHtml prefixMap))
|
||||
(set shortcutPanel.webview.html (shortcutPanelHtml strings))
|
||||
(shortcutPanel.webview.postMessage (object command "focus")))
|
||||
|
||||
(function shortcutPanelHtml [:PrefixMap<String> prefixMap]
|
||||
(function shortcutPanelHtml [:Map<String,String> keys]
|
||||
(let [&mut unusedKeys "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-/"
|
||||
shortcutParagraphs
|
||||
(for =>key shortcutKey prefixMap
|
||||
(for =>key rep keys
|
||||
(set unusedKeys (unusedKeys.replace key ""))
|
||||
"<p><strong>${key}</strong> - $(case shortcutKey
|
||||
((Prefix innerMap)
|
||||
"$(Lambda.count innerMap) shortcuts")
|
||||
((Final command)
|
||||
command)
|
||||
(otherwise))</p>")]
|
||||
"<p><strong>${key}</strong> - ${rep}</p>")]
|
||||
"<!DOCTYPE html>
|
||||
<html lang=\"en\">
|
||||
<head>
|
||||
|
@@ -18,7 +18,7 @@ interface ArchiveUI {
|
||||
*/
|
||||
var shortcutHandler(default, null):Null<KeyShortcutHandler<Entry>>;
|
||||
|
||||
function showPrefixMap(map:Map<String,ShortcutKey<Entry>>):Void;
|
||||
function showPrefixMap(map:Map<String,String>):Void;
|
||||
function hidePrefixMap():Void;
|
||||
|
||||
/**
|
||||
|
@@ -11,7 +11,7 @@
|
||||
{
|
||||
(when (and ui ui.shortcutHandler)
|
||||
(unless setup
|
||||
(set ui.shortcutHandler.onSelectPrefixMap ui.showPrefixMap)
|
||||
(set ui.shortcutHandler.onSelectPrefixMap ->:Void [_ map] (ui.showPrefixMap map))
|
||||
(set ui.shortcutHandler.onSelectItem
|
||||
->e {
|
||||
(ui.hidePrefixMap)
|
||||
|
@@ -46,7 +46,7 @@
|
||||
|
||||
(FlxG.camera.calculateScrollBounds entryGroup SCROLL_BOUND_MARGIN))
|
||||
|
||||
(method :Void showPrefixMap [:Map<String,ShortcutKey<Entry>> map]
|
||||
(method :Void showPrefixMap [:Map<String,String> map]
|
||||
(clearUI)
|
||||
(doFor =>key thing map
|
||||
(displayMessage "$key - $thing")))
|
||||
|
Reference in New Issue
Block a user