-
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
Remove inserter inside multi-selection #3246
Conversation
@@ -202,7 +204,8 @@ class VisualEditorBlockList extends Component { | |||
} | |||
|
|||
render() { | |||
const { blocks } = this.props; | |||
const { blocks, multiSelectedBlockUids } = this.props; | |||
const selectedWithoutLastUids = dropRight( multiSelectedBlockUids ); |
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.
🙈 More elegant solutions welcome.
Codecov Report
@@ Coverage Diff @@
## master #3246 +/- ##
==========================================
+ Coverage 34.65% 34.65% +<.01%
==========================================
Files 260 260
Lines 6741 6752 +11
Branches 1220 1225 +5
==========================================
+ Hits 2336 2340 +4
- Misses 3719 3723 +4
- Partials 686 689 +3
Continue to review full report at Codecov.
|
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.
Elsewhere I've been combatting frequent re-renders of this component where the common culprit is the multi-selection props (see #3247, #3170). I think we would be better served, both for intent and performance, to have more of a separation between multi-selection and block list rendering.
As it impacts here, I wonder if it should be the responsibility of the sibling inserter to determine if it should be visible (or return null
) depending on if the insertIndex
is within range of the current multi-selection?
@aduth Works for me too. Should we then pass down the multi selection props, or should it get all that itself? |
(Because the props are already present here.) |
It should get itself, since this will trigger a render only on the individual component when the prop changes. |
This is the issue though, since a change in reference value on |
@aduth I'm not sure how we'd avoid that though. Do you have any ideas? |
In this case I would suggest passing as a boolean prop into In a normal case I wouldn't be too bothered one way or the other whether this logic is controlled by the list component or the child itself, but since inserter is otherwise a simple component and the block list component is excessively complex, it could help readability to delegate this behavior to the child. In this specific circumstance, there's probably not much of a performance difference, only because we already have
|
685e1d9
to
f4d6ebf
Compare
Rebased and refactored according to review suggestions. I only now saw the reference to #3485; hopefully the two fixes can fix together nicely. |
@@ -220,6 +220,7 @@ class VisualEditorBlockList extends Component { | |||
/>, | |||
<VisualEditorSiblingInserter | |||
key={ 'sibling-inserter-' + uid } | |||
uid={ uid } | |||
insertIndex={ index + 1 } |
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.
With uid
being passed, can (and/or should) we determine insertIndex
in its connect
selector?
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.
can we? should we?
We can. To answer the question of should, I tried doing it in b3218c7. Looks OK enough; insertIndex
defaults to 0 to account for the one place where SiblingInsert was used without an associated uid
. That default is something you may object to. Let me know.
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 👍
@@ -748,6 +748,26 @@ export function isBlockSelected( state, uid ) { | |||
return start === uid; | |||
} | |||
|
|||
/** | |||
* Returns true if the block corresponding to the specified unique ID is | |||
* currently selected but isn't the last of the selected blocks. Here "last" |
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 seems like a strangely unexpected behavior for a function called isBlockWithinSelection
. On its name, I'd expect it to return true
if the block is anywhere in the current selection, regardless of multi-selection, singular selection, even considering block hierarchy (I arrive here from #15499 (comment) and relevant current logic of block list async rendering). Excluding the last block in the multi-selection is odd, even if for the particular requirements of the UI it's a necessary exclusion.
Do you think it's something which would make sense to revise the behavior and account for the UI needs in some other way, like a separate selector call to test whether the selected clientId is last in a multi-selection?
Description
Fixes #3076.
How Has This Been Tested?
Make a multi block selection. Make sure there are inserters around the block (visible by hover), but not inside the block.
Checklist: