On this amazing editor (Ace: Code Editor), there's a method which I can get the on change
event, is there a on keydown
event? Or a hack I can simulate it?
On this amazing editor (Ace: Code Editor), there's a method which I can get the on change
event, is there a on keydown
event? Or a hack I can simulate it?
2 Answers
Reset to default 13There is no keydown event, you can add keydown event listener on textarea returned by editor.textInput.getElement()
, but the better way is to use editor.mands.addCommand
editor.mands.addCommand({
name: "...",
exec: function() {},
bindKey: {mac: "cmd-f", win: "ctrl-f"}
})
or editor.keyBinding.addKeyboardHandler
I can't find it in the documentation, but in this discussion, I found out about the editor.mands.on('afterExec', ...)
API:
editor.mands.on('afterExec', eventData => {
if (eventData.mand.name === 'insertstring') {
console.log('User typed a character: ' + eventData.args);
}
});
afterExec
fires on every mand in the editor. Commands include actions like typed text, appearance of pletion popups on ctrl+space, etc...
It's not a direct analog of keydown event, but it is the thing I was googling for when I came here, so hopefully you'll find it useful.