[vscode] pass selectedText to shortcut commands

This commit is contained in:
2021-05-22 12:29:48 -06:00
parent d826755507
commit a52d86f142

View File

@@ -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,6 +100,9 @@
(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]
// Preserve the selected text and focused document before opening the webview:
(let [inputText (selectedText)
document .document activeTextEditor]
// When called without a prefixMap, if a shortcut panel is still open, close it and start over: // When called without a prefixMap, if a shortcut panel is still open, close it and start over:
(unless prefixMap (unless prefixMap
(when shortcutPanel (when shortcutPanel
@@ -121,9 +127,9 @@
((Final command) ((Final command)
(shortcutPanel.dispose) (shortcutPanel.dispose)
// TODO restore focus to previous frame first // TODO restore focus to previous frame first
(runCommand command)))} (_runCommand command inputText)))}
{(warningMessage "$key is not mapped to a shortcut in this context")(return)})))) {(warningMessage "$key is not mapped to a shortcut in this context")(return)}))))
(set shortcutPanel.webview.html (shortcutPanelHtml prefixMap))) (set shortcutPanel.webview.html (shortcutPanelHtml prefixMap))))
(defun shortcutPanelHtml [:Map<String,ShortcutKey> prefixMap] (defun shortcutPanelHtml [:Map<String,ShortcutKey> prefixMap]
(let [shortcutParagraphs (let [shortcutParagraphs