Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When pasting images, editing of text becomes very slow #1440

Open
mkrecek234 opened this issue Jan 5, 2024 · 4 comments
Open

When pasting images, editing of text becomes very slow #1440

mkrecek234 opened this issue Jan 5, 2024 · 4 comments

Comments

@mkrecek234
Copy link

Description

I am mostly using Trumbowyg on macOS Safari an have enabled the respective plugins to allow pasting images into the editor which are stored as base64 HTMLs.

However, when pasting an image, the text editing becomes very laggy and slow.

How to reproduce?

You can try it yourself on the trumbowyg demos webpage where after an image was pasted, text editing becomes very slow.

Any chance to speed this up, so it is still realistically usable for HTMLs with pasted images?

@lithxe
Copy link

lithxe commented Apr 15, 2024

Commenting to note that I have experienced this too, and limiting the size of the images down to a quite small 500px maximum on either side has helped a lot, though it will still be an issue if your users fill the text box with a bunch of images. This can be done in the trumbowyg.base64.js file down around line 143 within the if (isValidImage(e.target.result)) { function, something like:

var image = new Image();
image.src = e.target.result;

image.onload = function() { if(this.width > 500) { alert('Image is too large. Sorry! Files pasted in the editor have a limit of 500px on either side to avoid high load times.'); return false; } else if(this.height > 500) { alert('Image is too large. Sorry! Files pasted in the editor have a limit of 500px on either side to avoid high load times.'); return false; } else { trumbowyg.execCmd('insertImage', fReader.result, false, true); $(['img[src="', fReader.result, '"]:not([alt])'].join(''), trumbowyg.$box).attr('alt', values.alt); trumbowyg.closeModal(); } };

That being said, the issue was not apparent until we launched with the editor and it's definitely a pain point!

@Alex-D
Copy link
Owner

Alex-D commented May 21, 2024

Is it only on Safari?

@mkrecek234
Copy link
Author

mkrecek234 commented May 22, 2024

Is it only on Safari?

From my perception this is not only a Safari issue but also seen in Chrome: it seems solely to be an issue with slightly larger pictures. Question is why it slows it so much down, as while typing the image is simply "moved" and should ideally not consume so much CPU power.

@Alex-D
Copy link
Owner

Alex-D commented May 24, 2024

I think it's due to the synchronization between contenteditable and textarea, which makes a lot of data to transfer on each keystroke and update in the DOM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants