-
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
Rich Text: Remove restoreContentAndSplit #7618
Conversation
Funny enough, this will incidentally fix the issue described at #5095 (comment), which is still technically an issue for Some related discussion today in Slack with @tofumatt |
The end-to-end test failure is a legitimate bug where the caret is in the first paragraph wrongly when splitting in two from the middle: But in fact it's the same bug observed at #5095 (comment) and proposed to be fixed by #7620 . You can observe that it becomes fixed again if you cherry-pick 29bcba5 into your local branch. Thus, considering #7620 as a blocker for this. |
const beforeFragment = beforeRange.extractContents(); | ||
const afterFragment = afterRange.extractContents(); | ||
const beforeFragment = beforeRange.cloneContents(); | ||
const afterFragment = afterRange.cloneContents(); |
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 afterFragment
still be extracted, so we can avoid having to set it afterwards? I think this this happens in the block edit component. Or maybe I'm misunderstanding this.
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.
so we can avoid having to set it afterwards?
What do you mean by set?
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.
By means of setAttributes
in the block edit
function.
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.
Still not totally sure I understand, but we should want the explicit setAttribute
s and avoid leveraging any of these more implicit DOM mutations.
1085589
to
03edbac
Compare
03edbac
to
f3d3852
Compare
f3d3852
to
7a61eb0
Compare
Avoid destroying original content incurred by extractContents
Call `onSplit` directly
7a61eb0
to
03ded61
Compare
Rebased and force pushed. Running locally, all tests / functionality appears to work as expected now. |
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.
I tested this locally, split a bunch of blocks, paragraphs, lists, headings, including paragraphs that had bold characters and such–split them inside and outside the bold characters.
All seemed to work well and I encountered no bugs.
Writing a few e2e tests for block splitting would be good, I dunno if we have any. Either way I suppose that's not just related to this PR 😄
🚢
There's quite a few split across |
Related: https://github.com/WordPress/gutenberg/pull/5100/files#r198953121
This pull request seeks to simplify the
RichText
component, removing itsrestoreContentAndSplit
function which had been used to preserve content through a block split. In my testing, I had found that this was not a behavior caused by TinyMCE, as indicated by the function's comment, but rather in our use ofRange#extractContents
which moves (i.e. destroys) contents of a range. Updating this code to useRange#cloneContents
instead avoids the need to re-set theRichText
content which, in turn, should be a boon to performance and avoid the need for this pass-through function.Testing instructions:
Verify that there are no regressions in block splitting. Particularly, ensure that a paragraphs contents are not destroyed after pressing Enter within.