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