I have build a few custom plugins, but only one is listening to key events of the keyboard. Below in the code you can see the set-up to set the events. (and it\'s kinda bas
Editor#contentDom is fired every time new inner document is set up. In framed editor editor#setData()
replaces not only body.innerHTML
but entire document, so contentDom
is fired every time.
Thus, your code adds new listener on every setData()
but you don't remove the old one. For unclear reasons none of these two listeners are now fired on keydown
. I found out this recently and I cannot explain this fact.
Anyway, you need to detach all listeners on editor#contentDomUnload. Fortunately, there's convenient way to do that by using editable#attachListener.
editor.on( 'contentDom', function() {
var editable = editor.editable();
editable.attachListener( editor.document, 'keydown', function() {
...
} );
} );
Listener will be automatically detached on next contentDomUnload
.