-
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
[Writing Flow]: Try to fix multi-selection with shift+click
#40687
Conversation
const { | ||
isSelectionEnabled, | ||
getBlockParents, |
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.
These changes are unrelated - just some cleaning up.
Size Change: +116 B (0%) Total Size: 1.23 MB
ℹ️ View Unchanged
|
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 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. |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added an extra check about being a mouseup
event for now and let's see how this goes 😄
packages/block-editor/src/components/writing-flow/use-selection-observer.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/writing-flow/use-selection-observer.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/writing-flow/use-selection-observer.js
Outdated
Show resolved
Hide resolved
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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-observer
kicks 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+click
Before
before.mov
After
after.mov