-
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
Refactor: useBlockTools cleanup #59450
Conversation
Size Change: 0 B Total Size: 1.71 MB ℹ️ View Unchanged
|
const _showEmptyBlockSideInserter = | ||
clientId && | ||
! isTyping() && | ||
editorMode === 'edit' && | ||
isUnmodifiedDefaultBlock( { name, attributes } ); | ||
isUnmodifiedDefaultBlock( block ); |
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.
Let's reuse isEmptyDefaultBlock
here.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
selectedBlockClientIds() does quite a bit more work, when we only need one of the selected block ids. Generally, this will only be one block id. In the case of multiples, the previous method would get the topmost block in the selection in the array. getBlockSelectionStart gets the block where selection starts, which is a slightly different concept. Functionally, I think the outcome is identical, and getBlockSelectionStart should be faster.
53db6c6
to
616d285
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.
Is there anything holding this back outside an approving review? I pushed @Mamaduka 's nit and a comment about why we don't use the most likely selector.
} = select( blockEditorStore ); | ||
|
||
const selectedBlockClientIds = getSelectedBlockClientIds(); | ||
const selectedBlockClientId = selectedBlockClientIds[ 0 ]; | ||
const selectedBlockClientId = getBlockSelectionStart(); |
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.
Do you think adding a comment of why this is used (perf) instead of the selector that has the name matching the variable name is something future us will like?
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 someone would want to change this unless they knew why they were changing it, so maybe it's OK without the comment.
selectedBlockClientIds() does quite a bit more work, when we only need one of the selected block ids. Generally, this will only be one block id. In the case of multiples, the previous method would get the topmost block in the selection in the array. getBlockSelectionStart gets the block where selection starts, which is a slightly different concept. Functionally, I think the outcome is identical, and getBlockSelectionStart should be faster. Co-authored-by: Andrei Draganescu <andrei.draganescu@automattic.com> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
What?
Follow-up to #58979. @Mamaduka proposed some good ideas for improvements, but I wanted to do them in follow-ups instead of putting the changes into the first refactor.
Why?/How?
isUnmodifiedDefaultBlock
by passing the full block object.getBlockSelectionStart()
instead ofselectedBlockClientIds()
Testing Instructions
Toolbar should work in the same way as before.