NoelOConnell/quill-image-uploader

request: can insertEmbed set the source to user

Closed this issue · 3 comments

hey Noel,

Could you set the source to user when using insertEmbed here?
https://github.com/NoelOConnell/quill-image-uploader/blob/master/src/quill.imageUploader.js#L81

I'm using this plugin (it's great — thanks!) with ngx-quill (angular wrapper). The issue we've identified is if you upload an image using this plugin, you'll see it in the editor … but if we save the image is missing. I think ngx-quill does not pass the latest editor contents through, because the image insert isn't flagged as a user change. I'm guessing that means quill doesn't trigger the event that ngx-quill relies on.

I'm going off the explanation of user source here: https://quilljs.com/docs/api/#text-change

Changes may occur through an API but as long as they originate from the user, the provided source should still be "user". For example, when a user clicks on the toolbar, technically the toolbar module calls a Quill API to effect the change. But source is still "user" since the origin of the change was the user’s click.

APIs causing text to change may also be called with a "silent" source, in which case text-change will not be emitted. This is not recommended as it will likely break the undo stack and other functions that rely on a full record of text changes.

I think user is a good choice, but if you want to keep it open perhaps it could be a config setting?
Happy to send a PR if that helps.

cheers
Ben

Hi Ben,

I did a quick test and insertEmbed triggers a text-change event. So I'm not sure what event ngx-quill is listening for.

I think you are correct, since the user is taking the action to upload the image eg: clicking a button or pasting. It's safe to use "user" as the source.

I made that change and everything still worked the same.

It's released on npm now with version 1.2.1

Hope that solves your issue.

thanks Noel, much appreciated! :)

No problem, closing the issue now.

If you come across any other issues just let me know.