-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Fix don't show hover effect if the ancestor of a block is multi-selected #7613
Fix don't show hover effect if the ancestor of a block is multi-selected #7613
Conversation
let isMultiSelected = false; | ||
while ( ancestorUid && ! isMultiSelected ) { | ||
ancestorUid = getBlockRootUID( state, ancestorUid ); | ||
isMultiSelected = isBlockMultiSelected( state, ancestorUid ); |
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 believe we need some recursivity here in case we have more than one ancestor?
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.
Hi @youknowriad, yes we need to iterate over all the ancestors. We are doing it with the while ( ancestorUid && ! isMultiSelected ). The while cycle will only stop when we have no more ancestors or when we found a multi-selected ancestor.
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.
Oh gotcha missed it, I guess I was expecting a call to isAncestorMultiSelected
const { isHovered } = this.state; | ||
|
||
if ( isHovered || isMultiSelected || isSelected || |
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 feel like we can drop this.props.isMultiSelecting entirely and replace it with isPartOfMultiSelection
. Is there a use-case where we need both?
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.
The isMultiSelecting condition is required to avoid the hover effect when dragging the mouse to multi-select. There is a moment when adding a new block to a multi-selection where the block is not yet multi-selected and we are with the mouse over it without thus the hover would appear. The isMultiSelecting flag may be true while isPartOfMultiSelection maybe false.
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 don't think that's true because isPartOfMultiSelection = isMultiSelected || somethingElse
I was not taking about isMultiSelecting
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.
Ah, you mean dropping isMultiSelected entirely. If that's case in function maybeHover we are already doing it and we don't use isMultiSelected. But for other functions e.g: related to the block focus we should continue to use isMultiSelected because they want to check if the specific block is selected and not if the block or one ancestor is selected.
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 took a look at the other tests and I believe isPartOfMultiSelection
probably makes more sense there as well.
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.
Thank you for watching the use cases in detail. I applied your suggestion and I made some tests and the result looks great :)
b6aa978
to
6a062c1
Compare
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.
LGTM 👍
We might want to run npm run docs:build
(rebase first) each time we add a selector/action
Hi @youknowriad, unfortunately, I think our doc generation is not generating docs when createSelector is used, e.g: we don't have docs for getEditedPostContent. So in this case executing the command does not add the docs for the selector we are adding. |
@jorgefilipecosta Good catch, I'm limiting it to functions, I guess we can add also add the docs if it's a constant using |
Description
Fixes: #7361
Before even if a parent block was multi-selected we still showed the hover effect on the children. This PR's corrects that.
How has this been tested?
I added some paragraphs and images and columns block. Added some blocks inside the columns. I multi-selected the columns and some blocks. I verified the hover effect does not appear on the children of the columns. But still appears in other blocks.