fix Kiss-VSCode window focus from keyboard shortcuts
This commit is contained in:
@@ -84,11 +84,16 @@
|
||||
|
||||
(function :Void runCommand [&opt command] (_runCommand command))
|
||||
|
||||
(defMacro _runCommandFunc [commandName]
|
||||
`(let [command ,commandName]
|
||||
(set lastCommand command)
|
||||
(try ((dictGet commands command) inputText)
|
||||
(catch [error] (errorMessage "error from ${command}: $error") (return)))))
|
||||
|
||||
(function :Void _runCommand [&opt command inputText]
|
||||
(unless inputText (set inputText (selectedText)))
|
||||
(if command
|
||||
{(set lastCommand command) (try ((dictGet commands command) inputText)
|
||||
(catch [error] (errorMessage "error from ${command}: $error") (return)))}
|
||||
(_runCommandFunc command)
|
||||
(let [commandList
|
||||
(for description (commands.keys)
|
||||
(object
|
||||
@@ -99,9 +104,7 @@
|
||||
alwaysShow null))]
|
||||
(awaitLet [chosenCommand (quickPick commandList)]
|
||||
(when chosenCommand
|
||||
(set lastCommand chosenCommand.label)
|
||||
(try ((dictGet commands chosenCommand.label) inputText)
|
||||
(catch [error] (errorMessage "error from ${chosenCommand.label}: $error") (return))))))))
|
||||
(_runCommandFunc chosenCommand.label))))))
|
||||
|
||||
(function :Void runLastCommand [&opt _]
|
||||
(if lastCommand
|
||||
@@ -109,38 +112,43 @@
|
||||
(errorMessage "No Kiss command was run previously.")))
|
||||
|
||||
(var &mut :vscode.WebviewPanel shortcutPanel null)
|
||||
(var &mut :vscode.TextDocument documentBeforeShortcut null)
|
||||
(var &mut :String selectedTextBeforeShortcut null)
|
||||
|
||||
(function :Void showShortcutPanel [&opt :Map<String,ShortcutKey> prefixMap]
|
||||
// Preserve the selected text and focused document before opening the webview:
|
||||
(let [inputText (selectedText)]
|
||||
// When called without a prefixMap, if a shortcut panel is still open, close it and start over:
|
||||
(unless prefixMap
|
||||
(when shortcutPanel
|
||||
// TODO for some reason, method calling an object in (when [object] ...) context, resets the object's type to Any unless (the [Type]) is used
|
||||
(.dispose (the WebviewPanel shortcutPanel))
|
||||
(set shortcutPanel null))
|
||||
(set prefixMap commandShortcuts))
|
||||
(when shortcutPanel (shortcutPanel.dispose))
|
||||
(set shortcutPanel (Vscode.window.createWebviewPanel
|
||||
"kissShortcut"
|
||||
"Kiss Shortcuts"
|
||||
vscode.ViewColumn.Two
|
||||
(object
|
||||
enableScripts true)))
|
||||
// The keyListener handler needs to have access to the Disposible object to dispose itself, hence this let/set
|
||||
(let [&mut keyListener null]
|
||||
(set keyListener (shortcutPanel.webview.onDidReceiveMessage
|
||||
->key (if (prefixMap.exists key)
|
||||
{(keyListener.dispose)
|
||||
(case (dictGet prefixMap key)
|
||||
((Prefix innerMap)
|
||||
(showShortcutPanel innerMap))
|
||||
((Final command)
|
||||
(shortcutPanel.dispose)
|
||||
// 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))
|
||||
(shortcutPanel.webview.postMessage (object command "focus"))))
|
||||
(whenLet [text (selectedText)] (set selectedTextBeforeShortcut text))
|
||||
(when activeTextEditor (set documentBeforeShortcut activeTextEditor.document))
|
||||
|
||||
// When called without a prefixMap, if a shortcut panel is still open, close it and start over:
|
||||
(unless prefixMap
|
||||
(when shortcutPanel
|
||||
// TODO for some reason, method calling an object in (when [object] ...) context, resets the object's type to Any unless (the [Type]) is used
|
||||
(.dispose (the WebviewPanel shortcutPanel))
|
||||
(set shortcutPanel null))
|
||||
(set prefixMap commandShortcuts))
|
||||
(when shortcutPanel (shortcutPanel.dispose))
|
||||
(set shortcutPanel (Vscode.window.createWebviewPanel
|
||||
"kissShortcut"
|
||||
"Kiss Shortcuts"
|
||||
vscode.ViewColumn.Two
|
||||
(object
|
||||
enableScripts true)))
|
||||
// The keyListener handler needs to have access to the Disposible object to dispose itself, hence this let/set
|
||||
(let [&mut keyListener null]
|
||||
(set keyListener (shortcutPanel.webview.onDidReceiveMessage
|
||||
->key (if (prefixMap.exists key)
|
||||
{(keyListener.dispose)
|
||||
(case (dictGet prefixMap key)
|
||||
((Prefix innerMap)
|
||||
(showShortcutPanel innerMap))
|
||||
((Final command)
|
||||
(shortcutPanel.dispose)
|
||||
(Vscode.window.showTextDocument documentBeforeShortcut)
|
||||
(_runCommand command selectedTextBeforeShortcut)))}
|
||||
{(warningMessage "$key is not mapped to a shortcut in this context")(return)}))))
|
||||
(set shortcutPanel.webview.html (shortcutPanelHtml prefixMap))
|
||||
(shortcutPanel.webview.postMessage (object command "focus")))
|
||||
|
||||
(function shortcutPanelHtml [:Map<String,ShortcutKey> prefixMap]
|
||||
(let [shortcutParagraphs
|
||||
|
@@ -76,7 +76,7 @@
|
||||
"engines": {
|
||||
"vscode": "^1.4.0"
|
||||
},
|
||||
"version": "0.0.17",
|
||||
"version": "0.0.18",
|
||||
"activationEvents": [
|
||||
"onStartupFinished",
|
||||
"onCommand:kiss.runCommand",
|
||||
|
Reference in New Issue
Block a user