Repository navigation
[Writing Flow]: Try to fix multi-selection with shift+click - #40687
Conversation
| const { selectBlock } = useDispatch( blockEditorStore ); | ||
| const { | ||
| isSelectionEnabled, | ||
| getBlockParents, |
There was a problem hiding this comment.
These changes are unrelated - just some cleaning up.
|
Size Change: +116 B (0%) Total Size: 1.23 MB
ℹ️ View Unchanged
|
priethor
left a comment
There was a problem hiding this comment.
Thanks for the quick fix, @ntsekouras ❤️
I tested the use cases mentioned in #40636 and the issue is solved. I'm approving from a functional perspective but a technical review would be appreciated.
|
Thanks for testing @priethor! A technical review is required here for sure! 😄 Also in the end of reviews I'll add some e2e tests. |
talldan
left a comment
There was a problem hiding this comment.
This works well, thanks for fixing this one!
I left a few comments but they're all very minor and none are blockers.
In testing I noticed a few other multi-selection bugs, but they all seem to be in trunk so I'll make new issues.
| // If the selection has changed and we had pressed `shift+click`, | ||
| // we need to check if in an element that doesn't support | ||
| // selection has been clicked. | ||
| if ( event.shiftKey ) { |
There was a problem hiding this comment.
I wonder if this code should also check that it was a mouse event. While shiftKey doesn't seem to be defined for selectionchange events, I'm pretty sure it can be for other keyboard events. Event payloads can also be quite inconsistent between browsers.
There was a problem hiding this comment.
I added an extra check about being a mouseup event for now and let's see how this goes 😄
|
This is great, thanks for fixing so quickly @ntsekouras! |
* [Writing Flow]: Try to fix multi-selection with `shift+click` * change check with collapsed selection * address feedback * target specific mouse event with shift * add e2e tests
|
I cherry picked this change into |
| // Handle the case when we have a non-selectable block | ||
| // selected and click another one. | ||
| if ( startClientId !== selectedClientId ) { | ||
| startClientId = selectedClientId; | ||
| } |
There was a problem hiding this comment.
This block could just as well be refactored to:
startClientId = selectedClientId;… as there is no cost nor any side effect to the assignment.
And this brings me to asking the broader question: couldn't we simplify the logic here into something more straightforward, with fewer conditionals, as close as possible to:
if ( isClickShift ) { // This is the only branching that matters
startClientId = getBlockSelectionStart();
endClientId = getBlockClientId( event.target );
}wdyt, @ntsekouras?
What?
Fixes: #40636
From the issue:
Partial selection across blocks is handled mostly with the help of getSelection API. This creates some problems for blocks that have no text selection(ex Spacer) and things get even more complicated when we have blocks that have a Placeholder state, which actually contains text nodes. See @priethor 's comment:
How?
At first I tried adding some changes in use-click-selection, but couldn't make it work well at all, because selection changes in other events after that, and there are even more nuances to that for handling RichText selection first, before
use-selection-observerkicks in.I don't think this solution is perfect and handles all cases, and that's why suggestions and feedback is more than welcome. I have added comments in the code that will be helpful hopefully 😄
Testing Instructions
shift+clickBefore
before.mov
After
after.mov