[vscode] keyboard shortcuts
This commit is contained in:
@@ -98,9 +98,64 @@
|
|||||||
(runCommand lastCommand)
|
(runCommand lastCommand)
|
||||||
(errorMessage "No Kiss command was run previously.")))
|
(errorMessage "No Kiss command was run previously.")))
|
||||||
|
|
||||||
|
(defvar &mut :vscode.WebviewPanel shortcutPanel null)
|
||||||
|
(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:
|
||||||
|
(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))
|
||||||
|
(unless shortcutPanel
|
||||||
|
(set shortcutPanel (Vscode.window.createWebviewPanel
|
||||||
|
"kissShortcut"
|
||||||
|
"Kiss Shortcuts"
|
||||||
|
vscode.ViewColumn.Two
|
||||||
|
(object
|
||||||
|
enableScripts true))))
|
||||||
|
(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)))}
|
||||||
|
{(warningMessage "$key is not mapped to a shortcut in this context")(return)}))))
|
||||||
|
(set shortcutPanel.webview.html (shortcutPanelHtml prefixMap)))
|
||||||
|
|
||||||
|
(defun shortcutPanelHtml [:Map<String,ShortcutKey> prefixMap]
|
||||||
|
(let [shortcutParagraphs
|
||||||
|
(for =>key shortcutKey prefixMap
|
||||||
|
"<p><strong>${key}</strong> - $(case shortcutKey
|
||||||
|
((Prefix innerMap)
|
||||||
|
"$(Lambda.count innerMap) shortcuts")
|
||||||
|
((Final command)
|
||||||
|
command))</p>")]
|
||||||
|
"<!DOCTYPE html>
|
||||||
|
<html lang=\"en\">
|
||||||
|
<head>
|
||||||
|
<meta charset=\"UTF-8\">
|
||||||
|
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
|
||||||
|
<title>Kiss Shortcuts</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
$(shortcutParagraphs.join "")
|
||||||
|
<script>
|
||||||
|
const vscode = acquireVsCodeApi();
|
||||||
|
window.addEventListener('keydown', function (e) {
|
||||||
|
vscode.postMessage(e.key);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>"))
|
||||||
|
|
||||||
(defun :Void runKeyboardShortcut [&opt _]
|
(defun :Void runKeyboardShortcut [&opt _]
|
||||||
// TODO
|
(showShortcutPanel))
|
||||||
(errorMessage "Keyboard shortcut commands are not yet implemented"))
|
|
||||||
|
|
||||||
// Extract [k]eyboard [s]hortcuts from a string:
|
// Extract [k]eyboard [s]hortcuts from a string:
|
||||||
(defun extractKeyboardShortcuts [str &opt :Stream stream :String shortcuts]
|
(defun extractKeyboardShortcuts [str &opt :Stream stream :String shortcuts]
|
||||||
@@ -142,15 +197,14 @@
|
|||||||
(defun registerCommand [description command]
|
(defun registerCommand [description command]
|
||||||
(dictSet commands description command)
|
(dictSet commands description command)
|
||||||
(whenLet [keyboardShortcut (extractKeyboardShortcuts description)]
|
(whenLet [keyboardShortcut (extractKeyboardShortcuts description)]
|
||||||
(registerShortcut (keyboardShortcut.split "") description))
|
(registerShortcut (keyboardShortcut.split "") description)))
|
||||||
//(print commandShortcuts)
|
|
||||||
)
|
|
||||||
|
|
||||||
(defun :Void registerBuiltins []
|
(defun :Void registerBuiltins []
|
||||||
(set Prelude.print
|
(set Prelude.print
|
||||||
->[v] {
|
->[v] {
|
||||||
(infoMessage (Std.string v))
|
(infoMessage (Std.string v))
|
||||||
v})
|
v})
|
||||||
|
(registerCommand "Run a [k]iss command" runCommand)
|
||||||
(registerCommand "Rerun last command" runLastCommand)
|
(registerCommand "Rerun last command" runLastCommand)
|
||||||
(registerCommand "Run a keyboard shortcut command" runKeyboardShortcut)
|
(registerCommand "Run a keyboard shortcut command" runKeyboardShortcut)
|
||||||
(registerCommand "Evaluate and print a Kiss expression" evalAndPrint))
|
(registerCommand "Evaluate and print a Kiss expression" evalAndPrint))
|
||||||
|
@@ -37,11 +37,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"keybindings": [
|
"keybindings": [
|
||||||
{
|
|
||||||
"command": "kiss.runCommand",
|
|
||||||
"key": "ctrl+;",
|
|
||||||
"mac": "cmd+;"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"command": "kiss.runLastCommand",
|
"command": "kiss.runLastCommand",
|
||||||
"key": "ctrl+.",
|
"key": "ctrl+.",
|
||||||
@@ -49,8 +44,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"command": "kiss.runKeyboardShortcut",
|
"command": "kiss.runKeyboardShortcut",
|
||||||
"key": "ctrl+k",
|
"key": "ctrl+;",
|
||||||
"mac": "cmd+k"
|
"mac": "cmd+;"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"languages": [{
|
"languages": [{
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
(defvar &mut :KissConfig config null)
|
(defvar &mut :KissConfig config null)
|
||||||
|
|
||||||
(defun :Void tryLoadConfig [&opt :String text]
|
(defun :Void tryLoadConfig [&opt :String text]
|
||||||
|
// TODO if a config object is active and a shortcut panel is open, dispose the panel before we lose the handle in the current config object
|
||||||
(let [activeConfigPath (Path.join [activeConfigDir "config.js"])
|
(let [activeConfigPath (Path.join [activeConfigDir "config.js"])
|
||||||
backupConfigPath (Path.join [activeConfigDir (+ "config" (timeStamp) ".js")])]
|
backupConfigPath (Path.join [activeConfigDir (+ "config" (timeStamp) ".js")])]
|
||||||
// Backup existing config.js
|
// Backup existing config.js
|
||||||
|
Reference in New Issue
Block a user