Fix Ace editor saving keybinds and ex-commands

* Remove our manual keydown handler and use an Ace builtin function
* Define Vim's :write aka :w ex-command
This commit is contained in:
luukas 2022-06-14 02:45:17 +03:00
parent 392cf3d4e7
commit a67f069709
No known key found for this signature in database
GPG Key ID: CC4915E8D71FC044

View File

@ -278,6 +278,17 @@
let editor = ace.edit('editor');
editor.setTheme('ace/theme/dracula');
editor.session.setUseSoftTabs(true);
editor.commands.addCommand({
name: 'saveFile',
bindKey: {
win: 'Ctrl-S',
mac: 'Command-S',
sender: 'editor|cli'
},
exec: function(env, args, request) {
save()
}
});
// mouseup = css resize end
document.addEventListener("mouseup", function (e) {
@ -534,15 +545,6 @@
});
$('#editor').bind('keydown', function (event) {
file_loaded = true;
if (event.ctrlKey && event.key === 's') {
event.preventDefault();
save();
}
//console.log(event.keyCode);
});
setFileName();
$('#editorParent').toggle(false) // show
@ -1108,7 +1110,13 @@
function setKeyboard(target) {
var handlerName = target.getAttribute('data-handler-name');
if (handlerName == 'null') handlerName = null;
editor.setKeyboardHandler(handlerName);
editor.setKeyboardHandler(handlerName, () => {
if (handlerName == 'ace/keyboard/vim') {
require("ace/keyboard/vim").Vim.defineEx('write', 'w', function() {
save();
});
}
});
var nodes = target.parentNode.querySelectorAll("[data-handler-name]");
nodes.forEach(node => {