-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -165,15 +165,29 @@ export function useMultiSelection( clientId ) { | |||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if ( event.shiftKey ) { | ||||||||||||||||||||||||||
const blockSelectionStart = getBlockSelectionStart(); | ||||||||||||||||||||||||||
// Handle the case where we select a single block by | ||||||||||||||||||||||||||
// holding the `shiftKey` and don't mark this action | ||||||||||||||||||||||||||
// as multiselection. | ||||||||||||||||||||||||||
// By checking `blockSelectionStart` to be set, we handle the | ||||||||||||||||||||||||||
// case where we select a single block. We also have to check | ||||||||||||||||||||||||||
// the selectionEnd (clientId) not to be included in the | ||||||||||||||||||||||||||
// `blockSelectionStart`'s parents because the click event is | ||||||||||||||||||||||||||
// propagated. | ||||||||||||||||||||||||||
const startParents = getBlockParents( blockSelectionStart ); | ||||||||||||||||||||||||||
if ( | ||||||||||||||||||||||||||
blockSelectionStart && | ||||||||||||||||||||||||||
blockSelectionStart !== clientId | ||||||||||||||||||||||||||
blockSelectionStart !== clientId && | ||||||||||||||||||||||||||
! startParents?.includes( clientId ) | ||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||
toggleRichText( node, false ); | ||||||||||||||||||||||||||
multiSelect( blockSelectionStart, clientId ); | ||||||||||||||||||||||||||
const startPath = [ | ||||||||||||||||||||||||||
...startParents, | ||||||||||||||||||||||||||
blockSelectionStart, | ||||||||||||||||||||||||||
]; | ||||||||||||||||||||||||||
const endPath = [ | ||||||||||||||||||||||||||
...getBlockParents( clientId ), | ||||||||||||||||||||||||||
clientId, | ||||||||||||||||||||||||||
]; | ||||||||||||||||||||||||||
const depth = | ||||||||||||||||||||||||||
Math.min( startPath.length, endPath.length ) - 1; | ||||||||||||||||||||||||||
multiSelect( startPath[ depth ], endPath[ depth ] ); | ||||||||||||||||||||||||||
Comment on lines
+180
to
+190
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
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 commentThe 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 I'm going to merge and happy to follow up on this if it needs to 😄 |
||||||||||||||||||||||||||
event.preventDefault(); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} else if ( hasMultiSelection() ) { | ||||||||||||||||||||||||||
|
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:
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.
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.
Yes