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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RichText]: Fix wrong block merging when pressing delete
consecutively
#38991
Conversation
Size Change: +30 B (0%) Total Size: 1.15 MB
鈩癸笍 View Unchanged
|
Thanks @ntsekouras! It looks like this patch fixes the issue. Would it be possible to explain a bit further on what's happening here and why we need to Beforebefore.mp4Afterafter.mp4 |
PR also fixes #38991. Let's add a test case for this scenario as well. |
@gwwar I updated the PR's description but still waiting for Ella's input, as she has done a ton of stuff in RichText 馃槃 |
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.
Looks perfect to me :)
Fixes: #37534
Fixes #38991
Currently if you have some
mergeable
blocks likeparagraphs
and you pressdelete
at the end of one of them multiple times it doesn't work as expected.What is the problem and why this suggested patch
I'm not 100% sure if there is a better fix for this and I've pinged @ellatrix to take a look and share feedback, but from what I understood the reason for this is:
The delete handling happens here which takes its value from
useRichText
hook. After debugging I saw that the value wasn't updated ondelete
press and would stop afterthree
improper handlings of thedelete
, because in the third press would take another stale previous value, but the selection(start,end) would have changed so it wouldn't qualify to merge blocks.At first I thought we didn't check the new/previous value inside
useRichText
hook, but we actually do here. That hook on change updates internalrefs
(which do not cause a rerender) and after updating therefs
weforceRender
to make consumers take the updated value. So on merge blocks theonChange
is not called butapplyFromProps
is, which updates the usedref
without making the hook rerender.Hope that makes sense and I'm not way off with this solution 馃槃
Reproduction steps
There are two scenarios that are affected by the same problem.
Scenario 1:
first
paragraph pressdelete
multiple timesdelete
will merge the blocks and all the others are doing nothingScenario 2:
first
paragraph pressdelete
multiple timesdelete
will merge the two blocks and the second one will merge the third oneTesting instructions
With the reproduction steps everything should work as expected.