I am using tinymce 4.3.2 and I am trying to add a custom event when you press the tab key inside the editor. Here's my setup using the jquery plugin:
$(el).tinymce({
theme: "modern",
plugins: [
'textcolor'
],
toolbar: 'bold italic underline forecolor',
menubar: false,
statusbar: false,
setup: function(editor) {
editor.on('keyup', function(e) {
console.log('keyup event fired');
});
}
});
However, when I press the tab key, this keyup function does not seem to run.
I spent a lot of time thinking about this, and I hope to save someone from wasting a bunch of time on this. Seemed like the tab would go to the next element before the keyup event was able to be registered. The solution is to add a keydown event and prevent the default if you hit the tab key.
setup: function(editor) {
editor.on('keydown', function(e) {
var key = e.keyCode || e.which;
// do nothing on tab key
if (key == 9) {
e.preventDefault();
return;
}
}).on('keyup', function(e) {
console.log('keyup event fired');
});
}
success!