Skip to content

Commit

Permalink
adds a destructive way to clear selection
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu committed May 28, 2019
1 parent 4fce3af commit 79f22e0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,10 @@ _Returns_

Returns an action object used in signalling that the block selection is cleared.

_Parameters_

- _type_ `Object`: Object specifying if the clearing is destructive or not, default { destructive: false }.

_Returns_

- `Object`: Action object.
Expand Down
10 changes: 9 additions & 1 deletion packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,17 @@ export function multiSelect( start, end ) {
/**
* Returns an action object used in signalling that the block selection is cleared.
*
* @param {Object} type Object specifying if the clearing is destructive or not, default
* { destructive: false }.
*
* @return {Object} Action object.
*/
export function clearSelectedBlock() {
export function clearSelectedBlock( type = { destructive: false } ) {
if ( type.destructive === true ) {
return {
type: 'DESTRUCTIVELY_CLEAR_SELECTED_BLOCK',
};
}
return {
type: 'CLEAR_SELECTED_BLOCK',
};
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,8 @@ const BLOCK_SELECTION_INITIAL_STATE = {
*/
export function blockSelection( state = BLOCK_SELECTION_INITIAL_STATE, action ) {
switch ( action.type ) {
case 'DESTRUCTIVELY_CLEAR_SELECTED_BLOCK':
return BLOCK_SELECTION_INITIAL_STATE;
case 'CLEAR_SELECTED_BLOCK':
if ( isEqual( state, BLOCK_SELECTION_INITIAL_STATE ) ) {
return BLOCK_SELECTION_INITIAL_STATE;
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-post/src/store/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const effects = {
SWITCH_MODE( action ) {
// Unselect blocks when we switch to the code editor.
if ( action.mode !== 'visual' ) {
dispatch( 'core/block-editor' ).clearSelectedBlock();
dispatch( 'core/block-editor' ).clearSelectedBlock( { destructive: true } );
}

const message = action.mode === 'visual' ? __( 'Visual editor selected' ) : __( 'Code editor selected' );
Expand Down

0 comments on commit 79f22e0

Please sign in to comment.