-
Notifications
You must be signed in to change notification settings - Fork 4.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
RichText: Ensure that hitting enter at the end of a paragraph creates an empty paragraph #5034
Conversation
… an empty paragraph
d2d318b
to
c2cae09
Compare
c2cae09
to
023da3f
Compare
Empty content being inline boundary carets and empty text nodes
I've taken a few passes at refactoring this logic, which I've generalized to filtering out empty nodes when a split occurs, including empty text nodes and inline boundary placeholder nodes. This resolves a few related bugs present in master:
Master: An empty inline boundary fragment is included in the split paragraph
Master: An empty inline boundary fragment is included in the split paragraph |
Related: #1246 (comment) |
Aside: tinymce.DOM.isEmpty( 'Is this empty? ' )
// true Edit: Upon further testing, this has nothing to do with the caret placeholder, but rather that |
Isn't the problem when a new RichText instance is created? I adjusted the check in the constructor and that seems to work: https://github.com/WordPress/gutenberg/pull/4956/files#diff-766381e792acf9d4c2505f3aeddcca7eR111 Where the problem is |
* @return {boolean} Whether node is inline boundary. | ||
*/ | ||
export function isEmptyInlineBoundary( node ) { | ||
const text = node.nodeName === 'A' ? node.innerText : node.textContent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not just on links anymore right? Could happen for bold etc. as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, in fact, this fixes the previous issue of only accounting for anchor. We test any kind of node, but from what I've tested and assuming from the link plugin Utils.js is that it uses a different property to test (innerText
for links, textContent
for all others).
@@ -612,8 +655,7 @@ export class RichText extends Component { | |||
const afterFragment = afterRange.extractContents(); | |||
|
|||
const beforeElement = nodeListToReact( beforeFragment.childNodes, createTinyMCEElement ); | |||
const afterElement = isLinkBoundary( afterFragment ) ? [] : nodeListToReact( afterFragment.childNodes, createTinyMCEElement ); | |||
|
|||
const afterElement = nodeListToReact( filterEmptyNodes( afterFragment.childNodes ), createTinyMCEElement ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the same not happen on beforeElement
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue I'm seeing is that if the empty elements (br
) are in the middle of the after content, they are also removed from the newly created block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, this issue could happen in beforeElement
when you trigger Enter at the beginning of a paragraph block but in my testings the block is considered Empty properly.
Shouldn't we try to prevent this from ever occurring? That's what's being proposed in the latest changes here. |
In fact, with these changes, plus this bit of logic: gutenberg/blocks/rich-text/index.js Lines 381 to 382 in 4d835c0
...it seems we shouldn't need to manage const isEmpty = this.props.value.length === 0; ? Would be a nice simplification because we could drop all of the logic surrounding |
In 3476444, I updated |
@aduth Yes, ideally we would rely on the value for the |
Testing instructions