text-editor
text-editor copied to clipboard
"on:change" hook not fired when using keyboard shortcuts or inserting links
Hello there,
when using keyboard shortcuts like Ctrl+B or Ctrl+I, or inserting a link via the button, although the textarea content changes, the hook on:change is not being fired! How can I listen to all changes to the textarea?
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
This works for the button click:
editor._.hooks.set('on:change', function(){
alert('changed');
});
Other than that is a bug.
For now, you can do something like this:
function on_change() {
alert('changed');
}
editor._.hooks.set('exit.modal', on_change);
editor._.hooks.set('on:change', on_change);
["keydown", "cut", "paste", "input"].forEach(function($) {
TE._.events.set($, editor.target, on_change);
});
Thank you, I'll give that a try!
Hi @tovic,
while this helps with the shortcut keys, the "exit.modal" hook doesn't seem to do the trick. When inserting a link, the change is still not being triggered and thus my live preview is not being refreshed (thus resulting in a not-so-live preview... ;-)).
Yea, I’m in the way to refactor everything. Hopefully, these user inputs can be solved in the future.
Try to add focus to the event list:
["keydown", "cut", "paste", "input", "focus"].forEach( ... );
I had to rewrite the link modal handler anyway in order to add some extra functionality, so I ended up explicitly calling the on:change hook from within that callback, when a link is inserted. So this is solved for me, but of course the issue still persists for anyone using the build-in link modal.