I want to use Ace Editor for event handling purposes, but do not want the extra functionality and commands (toggle lines, multiple cursors, etc.), but only the default commands. Is there a quick way to do this?
My current approach is to create an array of the standardCommands in a textarea (not sure yet how to do that) and then to remove them from all commands like this:
//Returns the set difference of this array and arr array
Array.prototype.diff = function(arr) {
return this.filter(function(i) {return arr.indexOf(i) < 0;});
};
//Removes all Ace Editor commands which are not in the standardCommands array
function removeSpecialCommands(editor) {
var commands = Object.keys(editor.commands.commands); //gets all commands
var specialCommands = commands.diff(standardCommands); //gets extra ace cmnds
editor.commands.removeCommands(specialCommands); //removes those commands
}
However going through every command is not easy as many can't be called directly on the editor. So I'm not sure which commands are the standard ones. Is there a simpler way to get just the standard textarea commands (tab, insert, delete, movecursor with home, pgup, arrow keys, etc.)?
This depends a lot on what you consider to be a standard command. E.g. you mention tab
, but textareas do not handle tab
.
If your goal is to simply disable some commands that override default browser keys you might be interested in https://github.com/ajaxorg/ace/blob/master/lib/ace/keyboard/textarea.js
To also disable creating multiple selections with mouse use editor.setOption("enableMultiselect", false)
going through every command is not easy as many can't be called directly on the editor
all the editor commands can be called using editor.execCommand(commandName|commandObject)