[vscode] pass selectedText to shortcut commands
This commit is contained in:
@@ -74,9 +74,12 @@
|
|||||||
(awaitLet [kissStr (inputBox)]
|
(awaitLet [kissStr (inputBox)]
|
||||||
(infoMessage (Std.string (evalString kissStr)))))
|
(infoMessage (Std.string (evalString kissStr)))))
|
||||||
|
|
||||||
(defun :Void runCommand [&opt command]
|
(defun :Void runCommand [&opt command] (_runCommand command))
|
||||||
|
|
||||||
|
(defun :Void _runCommand [&opt command inputText]
|
||||||
|
(unless inputText (set inputText (selectedText)))
|
||||||
(if command
|
(if command
|
||||||
{(set lastCommand command) ((dictGet commands command) (selectedText))}
|
{(set lastCommand command) ((dictGet commands command) inputText)}
|
||||||
(let [commandList
|
(let [commandList
|
||||||
(for description (commands.keys)
|
(for description (commands.keys)
|
||||||
(object
|
(object
|
||||||
@@ -88,7 +91,7 @@
|
|||||||
(awaitLet [chosenCommand (quickPick commandList)]
|
(awaitLet [chosenCommand (quickPick commandList)]
|
||||||
(when chosenCommand
|
(when chosenCommand
|
||||||
(set lastCommand chosenCommand.label)
|
(set lastCommand chosenCommand.label)
|
||||||
((dictGet commands chosenCommand.label) (selectedText)))))))
|
((dictGet commands chosenCommand.label) inputText))))))
|
||||||
|
|
||||||
(defun :Void runLastCommand [&opt _]
|
(defun :Void runLastCommand [&opt _]
|
||||||
(if lastCommand
|
(if lastCommand
|
||||||
@@ -97,33 +100,36 @@
|
|||||||
|
|
||||||
(defvar &mut :vscode.WebviewPanel shortcutPanel null)
|
(defvar &mut :vscode.WebviewPanel shortcutPanel null)
|
||||||
(defun :Void showShortcutPanel [&opt :Map<String,ShortcutKey> prefixMap]
|
(defun :Void showShortcutPanel [&opt :Map<String,ShortcutKey> prefixMap]
|
||||||
// When called without a prefixMap, if a shortcut panel is still open, close it and start over:
|
// Preserve the selected text and focused document before opening the webview:
|
||||||
(unless prefixMap
|
(let [inputText (selectedText)
|
||||||
(when shortcutPanel
|
document .document activeTextEditor]
|
||||||
// TODO for some reason, method calling an object in (when [object] ...) context, resets the object's type to Any unless (the [Type]) is used
|
// When called without a prefixMap, if a shortcut panel is still open, close it and start over:
|
||||||
(.dispose (the WebviewPanel shortcutPanel))
|
(unless prefixMap
|
||||||
(set shortcutPanel null))
|
(when shortcutPanel
|
||||||
(set prefixMap commandShortcuts))
|
// TODO for some reason, method calling an object in (when [object] ...) context, resets the object's type to Any unless (the [Type]) is used
|
||||||
(unless shortcutPanel
|
(.dispose (the WebviewPanel shortcutPanel))
|
||||||
(set shortcutPanel (Vscode.window.createWebviewPanel
|
(set shortcutPanel null))
|
||||||
"kissShortcut"
|
(set prefixMap commandShortcuts))
|
||||||
"Kiss Shortcuts"
|
(unless shortcutPanel
|
||||||
vscode.ViewColumn.Two
|
(set shortcutPanel (Vscode.window.createWebviewPanel
|
||||||
(object
|
"kissShortcut"
|
||||||
enableScripts true))))
|
"Kiss Shortcuts"
|
||||||
(let [&mut keyListener null]
|
vscode.ViewColumn.Two
|
||||||
(set keyListener (shortcutPanel.webview.onDidReceiveMessage
|
(object
|
||||||
->key (if (prefixMap.exists key)
|
enableScripts true))))
|
||||||
{(keyListener.dispose)
|
(let [&mut keyListener null]
|
||||||
(case (dictGet prefixMap key)
|
(set keyListener (shortcutPanel.webview.onDidReceiveMessage
|
||||||
((Prefix innerMap)
|
->key (if (prefixMap.exists key)
|
||||||
(showShortcutPanel innerMap))
|
{(keyListener.dispose)
|
||||||
((Final command)
|
(case (dictGet prefixMap key)
|
||||||
(shortcutPanel.dispose)
|
((Prefix innerMap)
|
||||||
// TODO restore focus to previous frame first
|
(showShortcutPanel innerMap))
|
||||||
(runCommand command)))}
|
((Final command)
|
||||||
{(warningMessage "$key is not mapped to a shortcut in this context")(return)}))))
|
(shortcutPanel.dispose)
|
||||||
(set shortcutPanel.webview.html (shortcutPanelHtml prefixMap)))
|
// TODO restore focus to previous frame first
|
||||||
|
(_runCommand command inputText)))}
|
||||||
|
{(warningMessage "$key is not mapped to a shortcut in this context")(return)}))))
|
||||||
|
(set shortcutPanel.webview.html (shortcutPanelHtml prefixMap))))
|
||||||
|
|
||||||
(defun shortcutPanelHtml [:Map<String,ShortcutKey> prefixMap]
|
(defun shortcutPanelHtml [:Map<String,ShortcutKey> prefixMap]
|
||||||
(let [shortcutParagraphs
|
(let [shortcutParagraphs
|
||||||
|
|||||||
Reference in New Issue
Block a user