-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Node#isEmpty considers nbsp-only node as non-empty #4466
Comments
An element is only considered empty if there is no caret positions or just white space. However nbsp is considered contents since it's a padded paragraph. Not exactly sure why you need this but you can disable the padding behavior of paragraphs by setting for example We need a really good reason to break the isEmpty functionality and consider padded block elements as empty. So would be nice if we could get a use case where this is needed. |
Here's a more direct example, where a brand new (empty) initialization of the editor reports as being non-empty: http://fiddle.tinymce.com/1ygaab/1 To me, it seems like the semantics of being empty should trump whether there's a padded node there. If I initialized the editor with no content, should it not be considered empty? I'll dig to see if there was a case in Gutenberg we encountered this. We decided against the tree format, so it may not be a pressing need at the moment, but still seems like an unexpected behavior. |
This was originally discovered in WordPress/gutenberg#7583, which was a closed experiment of using |
Hey Aduth, we are looking into this. Trying to understand what/how you need this. Wouldn't adding something like editor.isEmpty() not work better in this case? As you said, your not using the |
As far as prioritization, this isn't actively affecting us in Gutenberg. I do think it's a legitimate issue to consider for anyone who might want to use the tree nodes result. We've / I've explored it on a few occasions, and it seems like it would be a more compatible option, but based on previous findings we're not exploring it further at this time. |
Do you want to request a feature or report a bug?
Bug. (Or verification of intent).
What is the current behavior?
When a new block is created, it is padded with an
non-breaking space character. The behavior ofNode#isEmpty
disregards whitespace, but not specifically the non-breaking space character.If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via fiddle.tinymce.com or similar.
Demo: http://fiddle.tinymce.com/Pugaab
Enter some content and press Enter.
More directly, it could be reproduced by a test case on creating an empty text node.
Possible solution: If changing the regular expression to use
,
\s
instead ofisEmpty
correctly returnstrue
.Before:
tinymce/src/core/main/ts/api/html/Node.ts
Line 14 in 7dfd810
After:
What is the expected behavior?
The logged result should show "Is empty: true" since it is for the newly-created empty paragraph.
Which versions of TinyMCE, and which browser / OS are affected by this issue? Did this work in previous versions of TinyMCE?
TinyMCE 4.7.13
Unaware of previous working state.
The text was updated successfully, but these errors were encountered: