-
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
Clear selection state when RESET_BLOCKS action is dispatched #21371
Conversation
Size Change: +1 B Total Size: 884 kB
ℹ️ View Unchanged
|
@@ -1094,6 +1094,8 @@ function selection( state = {}, action ) { | |||
|
|||
return { clientId: blockToSelect.clientId }; | |||
} | |||
case 'RESET_BLOCKS': | |||
return {}; |
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 is a pretty basic solution at the moment and it doesn't cover that there might be cases where selection should be retained. Maybe if the client id for the currently selected block exists in the blocks array from the RESET_BLOCKS
action?
It looks like RESET_BLOCKS
is used for synchronizing templates, so that looks like a case where selection could be unexpectedly lost.
However, with multi-selections, trying to retain a selection might cause a situation where selectionStart
is retained but selectionEnd
is cleared or vice versa.
Description
In #21340 a fix toolbar is used for the new Navigation Menus page that's being developed as an experimental feature.
@draganescu noticed an issue when testing this and changing between menus (#21340 (review)), which seems to be due to block selection state not being reset when
RESET_BLOCKS
is dispatched by the new menu selection.How has this been tested?
This can fairly easily be reproduced in the post editor:
wp.data.dispatch('core/block-editor').resetBlocks([]);
master
they're displayed and clicking on the more menu causes the editor to throw an error.)Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: