-
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
[Block Editor]: Fix selection by holding shift key for nested blocks #35668
[Block Editor]: Fix selection by holding shift key for nested blocks #35668
Conversation
if ( | ||
blockSelectionStart && | ||
blockSelectionStart !== clientId | ||
blockSelectionStart !== clientId && | ||
! startParents?.includes( clientId ) |
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.
@ellatrix I'm not sure if there is a more elegant way to handle this or in another place..
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 for when we shift+click in a parent of the selected block, right? What should the outcome be for that case? Do we need a test here too?
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.
AFAIU, it's for this case:
- Pressing shift + click within a rich-text block nested inside a nested block like
Group
Currently, when you do that, you can't really edit the block anymore, see #33665. So this line is supposed to fix that behavior. In practice, for what I see, it highlights the text between the cursor location, and the location that's being shift-clicked.
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.
Do we need a test here too?
I think it's covered by this e2e test, isn't it?
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 think it's covered by this e2e test, isn't it?
Yes
Size Change: -5.22 kB (0%) Total Size: 1.07 MB
ℹ️ View Unchanged
|
const startPath = [ | ||
...startParents, | ||
blockSelectionStart, | ||
]; | ||
const endPath = [ | ||
...getBlockParents( clientId ), | ||
clientId, | ||
]; | ||
const depth = | ||
Math.min( startPath.length, endPath.length ) - 1; | ||
multiSelect( startPath[ depth ], endPath[ depth ] ); |
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.
It seems like this is pretty much the same logic as
gutenberg/packages/block-editor/src/components/block-list/use-block-props/use-multi-selection.js
Lines 93 to 104 in b29c09d
const startPath = [ | |
...getBlockParents( clientId ), | |
clientId, | |
]; | |
const endPath = [ | |
...getBlockParents( endClientId ), | |
endClientId, | |
]; | |
const depth = | |
Math.min( startPath.length, endPath.length ) - 1; | |
multiSelect( startPath[ depth ], endPath[ depth ] ); |
Should we extract it into a small helper method, or share it otherwise?
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 thought about it but in the second case we use the parents for another check before, so a shared util for our 2 cases would end up passing the start/end paths and just having the Math.min
in there, so I'm not really sure it's worth it..
I'm going to merge and happy to follow up on this if it needs to 😄
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.
Thanks Nik! Confirming that this fixes the issue. Code LGTM, too!
Awesome videos and e2e coverage! 👏
…35668) * [Block Editor]: Fix selection by holding shift key for nested blocks * add e2e tests
I'm not sure if this PR is related, but I get the sense that it may have tried to fix an issue that is similar to what I'm seeing at the moment, which is that after having edited content for a bit, the title block becomes inert: I don't have specific steps to reproduce, other than to start editing some content, waiting for a bit, saving, then trying to edit the title. Sometimes it continues to work, sometimes it breaks. |
@jasmussen this PR had to do specifically with holding |
Part of: #35662
Fixes: #33665
There are currently two bugs in selection when holding
shift
key that result in locking the user out of editing.Group
Group
blocks.Before
Screeny.Video.14.Oct.2021.at.18.41.39.mov
and
bug.mov
After
Screen.Recording.2021-10-15.at.3.05.24.PM.mov
In my videos the different
Group
blocks have different background colors.