-
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
Fix don't show hover effect if the ancestor of a block is multi-selected #7613
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 |
---|---|---|
|
@@ -930,6 +930,30 @@ export function isBlockMultiSelected( state, uid ) { | |
return getMultiSelectedBlockUids( state ).indexOf( uid ) !== -1; | ||
} | ||
|
||
/** | ||
* Returns true if an ancestor of the block is multi-selected and false otherwise. | ||
* | ||
* @param {Object} state Global application state. | ||
* @param {string} uid Block unique ID. | ||
* | ||
* @return {boolean} Whether an ancestor of the block is in multi-selection set. | ||
*/ | ||
export const isAncestorMultiSelected = createSelector( | ||
( state, uid ) => { | ||
let ancestorUid = uid; | ||
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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Oh gotcha missed it, I guess I was expecting a call to |
||
} | ||
return isMultiSelected; | ||
}, | ||
( state ) => [ | ||
state.editor.present.blockOrder, | ||
state.blockSelection.start, | ||
state.blockSelection.end, | ||
], | ||
); | ||
/** | ||
* Returns the unique ID of the block which begins the multi-selection set, or | ||
* null if there is no multi-selection. | ||
|
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 aboutisMultiSelecting
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 :)