-
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
Fix select all shortcut inside widget area parents #30462
Conversation
Size Change: +195 B (0%) Total Size: 1.42 MB
ℹ️ View Unchanged
|
My first thought while reading this is that it sounds like yet another problem with using the Widget Area block to implement widget areas 🙂 cc. @talldan |
@@ -45,13 +77,32 @@ function KeyboardShortcuts() { | |||
{ bindGlobal: true } | |||
); | |||
|
|||
useShortcut( | |||
'core/edit-widgets/select-all', | |||
useCallback( |
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 it necessary to memoize it?
'core/widget-area' | ||
); | ||
return { | ||
rootBlocksClientIds: getBlockOrder( selectedParentClientId ), |
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.
Since we only care about the first and the last, maybe try to only expose them here so that we can avoid unnecessary re-renders.
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editWidgetsStore } from '../../store'; | ||
|
||
let 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.
A better "React" way of doing this is to convert this to a ref with useRef
. I'm not sure why we need this variable either? Couldn't we just use newSelectedClientId
?
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.
We can't because it's updated on render once the selection is changed. We need to maintain a reference to the "selected" block when the keyboard shortcut was fired.
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.
Hmm, I'm not sure I follow.
Do you mean we can't convert this to a ref or we can't use newSelectedClientId
? I think either way this deserves some comments 😆.
I think the implementation would be a lot cleaner here if the majority of it were implemented as an action (e.g. The problem architecturally with the current implementation is that we're using Instead, we want to determine the blocks to select when the user actually presses the shortcut. Doing it that way will also be more performant as we won't be running selectors unnecessarily during render. |
Will be fixed by #31859 |
Description
Fixes #28267. The "select all" functionality in the post editor assumes that there is no boundary block and so it defaults to selecting everthing. On the widgtets editor we have a widget area block that contains the blocks for that area and it makes no sense to select via Primary + A the blocks in another area.
This fix is also part of my investigation in fixing #19102 and it may contain a way to fix that.
I am not happy with this implementation, but it does work. The downside is creating a memory store or hardcoding a block name for determining the container.
Alternatives would be:
selectable
supports where by certain blocks will not be selectable and select all will only apply to theirinnerBlocks
The other place that has this problem is the site editor where select all is selecting across template parts which might not be expected, but at least there we don't have the visual and functional separation active in the widgets editor.
How has this been tested?
Tested locally by:
Screenshots
N/A
Types of changes
Added an overrride for the edit-widgets package of the 'core/block-editor/select-all' shortcut.
Updated the select all logic by remembering the first selection, finding the parent and preserving the list of the blocks in the top most widget area.
To Do
Checklist:
*.native.js
files for terms that need renaming or removal).