Skip to content
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

Maybe update block selection on UNDO/REDO actions #12188

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/editor/src/store/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { _n, sprintf } from '@wordpress/i18n';
* Internal dependencies
*/
import {
clearSelectedBlock,
setupEditorState,
replaceBlocks,
selectBlock,
Expand All @@ -33,6 +34,7 @@ import {
getBlocks,
getBlockCount,
getPreviousBlockClientId,
getSelectedBlock,
getSelectedBlockClientId,
getSelectedBlockCount,
getTemplate,
Expand Down Expand Up @@ -123,6 +125,15 @@ export function selectPreviousBlock( action, store ) {
}
}

export function maybeUpdateBlockSelection( action, store ) {
if ( !! getSelectedBlock( store.getState() ) ) {
// do nothing if block exists
return;
}
// otherwise, clear block selection
clearSelectedBlock();
}

/**
* Effect handler which will return a default block insertion action if there
* are no other blocks at the root of the editor. This is expected to be used
Expand Down Expand Up @@ -270,4 +281,6 @@ export default {
/* translators: %s: number of selected blocks */
speak( sprintf( _n( '%s block selected.', '%s blocks selected.', blockCount ), blockCount ), 'assertive' );
},
UNDO: maybeUpdateBlockSelection,
REDO: maybeUpdateBlockSelection,
};