text-editor icon indicating copy to clipboard operation
text-editor copied to clipboard

"on:change" hook not fired when using keyboard shortcuts or inserting links

Open Connum opened this issue 7 years ago • 6 comments

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.

Connum avatar Sep 05 '18 13:09 Connum

This works for the button click:

editor._.hooks.set('on:change', function(){
    alert('changed');
});

Other than that is a bug.

taufik-nurrohman avatar Sep 05 '18 14:09 taufik-nurrohman

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);
});

taufik-nurrohman avatar Sep 05 '18 14:09 taufik-nurrohman

Thank you, I'll give that a try!

Connum avatar Sep 05 '18 14:09 Connum

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... ;-)).

Connum avatar Sep 06 '18 13:09 Connum

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( ... );

taufik-nurrohman avatar Sep 06 '18 14:09 taufik-nurrohman

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.

Connum avatar Sep 15 '18 12:09 Connum