Closed thiagolacerda closed 4 years ago
This issue has been closed due to inactivity. Tiny will soon be working with members of the community to close other old issues on our GitHub repositories.
Please note the official support window for TinyMCE 4 is ending on December 31, 2020. If you haven't already upgraded to TinyMCE 5 it is highly encouraged that you do so. Upgrading will give you access to the latest releases and updates made to our WYSIWYG editor focused on bringing the latest UX and developer features into the editing experience. To assist with upgrading the editor we have put together a migration guide you can use here - https://www.tiny.cloud/blog/how-to-migrate-from-tinymce-4-to-tinymce-5/
If you have any questions or concerns, you can contact me at community-qa@tiny.cloud. You can also join the discussion on our mailing list at the following link: community-qa+subscribe@tiny.cloud.
When you select a text with spaces, that are in the same node, for example (the | denotes the start and end of a selection):
<span>|Example |Here</span>
Tinymce gets the text and sees that it has a whitespace in the last character position of the string. It removes such whitespace and apply the formatting to the remainder of the text. That would result in an html like this, supposing we applied Arial font and did not changed the selection:
<span style="font-family:Arial;">|Example</span><span> |Here</span>
As you can see, now the selection is over two different span nodes.
If you apply the formatting again, TinyMCE will get a different Range object that will have the startContainer as the first text node ("Example") and the endContainer as the second Text node (" Here") with the endOffset indicating that the text that we want to format ends at the first space of the second Text node. When TinyMCE goes with its process of removing trailing spaces, it notices that the whole text to be formatted of the endContainer selection is just a whitespace, so it does not remove it, assuming that you really want to format that whitespace.
The part of the code that removes the trailing spaces from the range: https://github.com/tinymce/tinymce/blob/f4011bc6c4fb07141de9603b5a3cb1e7595d7243/src/core/src/main/js/Formatter.js#L1848
This is a very inconsistent behavior making the user very confused if the formatting that he actually applied worked or not. I believe that most of the time, if the space is selected as part of a text, the user really wants to format that space too. If it was by mistake, they can go and undo the format on that space.
I'm using TinyMCE 4.5.6 and that happens on all browsers (IE, FF, Chrome) that I tested