From 31d37491eedbdb0d03785631bd66ec49d7b829e6 Mon Sep 17 00:00:00 2001 From: MaxCan-Code <35848843+MaxCan-Code@users.noreply.github.com> Date: Sun, 3 Mar 2024 11:30:16 -0500 Subject: [PATCH] Add sample vim extension --- sample-extensions/package-lock.json | 26 ++++++++++++ sample-extensions/package.json | 5 +++ sample-extensions/vim.js | 62 +++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 sample-extensions/package-lock.json create mode 100644 sample-extensions/package.json create mode 100644 sample-extensions/vim.js diff --git a/sample-extensions/package-lock.json b/sample-extensions/package-lock.json new file mode 100644 index 000000000..9a1e24154 --- /dev/null +++ b/sample-extensions/package-lock.json @@ -0,0 +1,26 @@ +{ + "name": "sample-extensions", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "monaco-vim": "^0.4.1" + } + }, + "node_modules/monaco-editor": { + "version": "0.46.0", + "resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.46.0.tgz", + "integrity": "sha512-ADwtLIIww+9FKybWscd7OCfm9odsFYHImBRI1v9AviGce55QY8raT+9ihH8jX/E/e6QVSGM+pKj4jSUSRmALNQ==", + "peer": true + }, + "node_modules/monaco-vim": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/monaco-vim/-/monaco-vim-0.4.1.tgz", + "integrity": "sha512-+cy0TE9xarjLIgUexqxIEbat3K1l7WbiFSLZKAO2kYl1qFRvkeWn4ro/C4c6dK0i9+WQKUC4Dhu/nyCbZfA37w==", + "peerDependencies": { + "monaco-editor": "*" + } + } + } +} diff --git a/sample-extensions/package.json b/sample-extensions/package.json new file mode 100644 index 000000000..421dbf6dd --- /dev/null +++ b/sample-extensions/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "monaco-vim": "^0.4.1" + } +} diff --git a/sample-extensions/vim.js b/sample-extensions/vim.js new file mode 100644 index 000000000..d8b32de56 --- /dev/null +++ b/sample-extensions/vim.js @@ -0,0 +1,62 @@ +//To use this extension: +// copy this file to the userData dir as in https://dyalog.github.io/ride/4.5/customising_your_session: +// (package.json and package-lock.json are there for reference) +// - Linux: `$HOME/.config/Ride-` +// - macOS: `$HOME/Library/Application Support/Ride-` (hidden directory – access from the command line) +// - Microsoft Windows: `%APPDATA%\Ride-` +// npm install --prefix /dir/to/this/file monaco-vim +// export RIDE_JS=/path/to/this/file.js +//before starting RIDE. +$.extend(D.commands, { + VIM(me) { + amdRequire( + [ + "vs/editor/editor.main", + `${D.el.app.getPath("userData")}/node_modules/monaco-vim/dist/monaco-vim`, + ], + (a, MonacoVim) => { + vimMode = MonacoVim.initVimMode( + me, + document.getElementById("sb_vim") + ? (() => { + const x = document.getElementById("sb_vim"); + x.replaceChildren(); + return x; + })() + : document.getElementById("sb_left").appendChild( + (() => { + const x = document.createElement("div"); + x.setAttribute("id", "sb_vim"); + return x; + })(), + ), + ); + }, + ); + me.updateOptions({ + lineNumbers: "relative", + autoClosingQuotes: "always", + autoClosingBrackets: "always", + }); + }, + MIV() { vimMode.dispose(); }, +}); +D.remDefaultMap = (me) => { + // hijack to run additional code on startup + const kbs = me._standaloneKeybindingService; + kbs.addDynamicKeybinding( + "-editor.action.insertCursorAtEndOfEachLineSelected", + null, + () => {}, + ); + kbs.addDynamicKeybinding("-editor.action.blockComment", null, () => {}); + kbs.addDynamicKeybinding("-editor.action.formatDocument", null, () => {}); + D.commands.VIM(me); +}; +$.extend(D.Ed.prototype, { + setLN(x) { + // update the display of line numbers and the state of the "[...]" button + this.me.updateOptions({ lineNumbers: "relative" }); + this.dom.querySelector(".tb_LN").classList.toggle("pressed", !!x); + }, +});