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?
The keydown event is fired when a key is pressed. Unlike the deprecated keypress event, the keydown event is fired for all keys, regardless of whether they produce a character value. The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered.
The onkeydown attribute fires when the user is pressing a key (on the keyboard).
There 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.commands.addCommand
editor.commands.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.commands.on('afterExec', ...)
API:
editor.commands.on('afterExec', eventData => {
if (eventData.command.name === 'insertstring') {
console.log('User typed a character: ' + eventData.args);
}
});
afterExec
fires on every command in the editor. Commands include actions like typed text, appearance of completion 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With