Alex-D / Trumbowyg

A lightweight and amazing WYSIWYG JavaScript editor under 10kB
https://alex-d.github.io/Trumbowyg
MIT License
3.99k stars 612 forks source link

Cleanpaste plugin doesn't work #1258

Open tveimo opened 2 years ago

tveimo commented 2 years ago

The cleanpaste plugin doesn't seem to receive any pasted text. If I move the code that fetches the pasted data to outside the setTimeout() handler, then it is able to get the data ok;

trumbowyg.pasteHandlers.push(function (pasteEvent) {
  var clipboardData = (pasteEvent.originalEvent || pasteEvent).clipboardData,
  pastedData = clipboardData.getData('text/html');
  setTimeout(function () {
    try {
    [...]
    }
timler commented 2 years ago

Unfortunately the code change above isn't enough to fix this plugin (at least IMHO). There are a few more bugs that I don't think it's worth ironing out. I think the change that was made on the commit ad605a7812a97a843e7b953821f8b70e3134bb4e broke everything. Although I think the premise was good - to work on only the pasted content, things seem to go wrong when the content is inserted because it's already inserted.

The other paste plugin AllowTagsFromPate (link) is better, although it also works on the entire HTML document.

ulysse06610 commented 11 months ago

Hello, with the new plugin i've got a problem because it cleans the content before the pasted text was pasted. The solution i've found is to use setTimeout

  trumbowyg.pasteHandlers.push(function () {
                        try {
                             setTimeout(function () {
                            trumbowyg.$ed.html(cleanIt(trumbowyg.$ed.html()));
                        }, 2000);