Alex-D / Trumbowyg

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

empty() does not work properly #1329

Closed philippehenri closed 1 year ago

philippehenri commented 1 year ago

When pasting a colored text copied from Word, and deleting it immediately, any new char typed has the font and color of the pasted text (even after calling empty() ??

Description

on MAC, Chrome

How to reproduce?

As explained above:

1/ select some red text copied from word for example 2/ paste it (here for example : https://alex-d.github.io/Trumbowyg/demos/ ) 3/ delete it 4/ type some chars... -> they are red ??

Alex-D commented 1 year ago

It is a browser-level issue I think :/ Can't do much here, sorry

philippehenri commented 1 year ago

thanks. ps: I just found an easy fix that you might want to add to your empty() function. I have added this line after calling empty():

            document.execCommand('insertHTML', false, ''); 

it works with chrome, safari, opera and firefox on MAC (not tested on windows). it resets all font, color, etc...

Alex-D commented 1 year ago

I see that, Maybe it could be added in a next version since we do not have to support IE these days

Alex-D commented 1 year ago

Maybe I can add this to the next version since we do not have to support IE these days :) Thank you for the tip!

philippehenri commented 1 year ago

you are welcome, thank you for the great product.

ps: fyi, there is another working solution as I read that execcommand is or will soon be deprecated:

            $('.trumbowyg-editor').html(' ');
            setTimeout(function () {
              $('.trumbowyg-editor').html('');
            },100);

note: $('.trumbowyg-editor').html('') alone does not work for some reason...