Skip to content

Commit

Permalink
adds destructive selection clearer and clears on visual edititng togg…
Browse files Browse the repository at this point in the history
…le and manual deselection
  • Loading branch information
draganescu committed Jun 2, 2019
1 parent 79f22e0 commit 5709b2f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ class BlockSelectionClearer extends Component {
const {
hasSelectedBlock,
hasMultiSelection,
clearSelectedBlock,
wipeSelectedBlock,
} = this.props;

const hasSelection = ( hasSelectedBlock || hasMultiSelection );
if ( event.target === this.container && hasSelection ) {
clearSelectedBlock();
wipeSelectedBlock();
}
}

Expand Down Expand Up @@ -68,7 +68,7 @@ export default compose( [
};
} ),
withDispatch( ( dispatch ) => {
const { clearSelectedBlock } = dispatch( 'core/block-editor' );
return { clearSelectedBlock };
const { wipeSelectedBlock } = dispatch( 'core/block-editor' );
return { wipeSelectedBlock };
} ),
] )( BlockSelectionClearer );
18 changes: 12 additions & 6 deletions packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ export function multiSelect( start, end ) {
};
}

/**
* Returns an action object used in signalling that the block selection is cleared.
*
* @return {Object} Action object.
*/
export function wipeSelectedBlock() {
return {
type: 'WIPE_SELECTED_BLOCK',
};
}

/**
* Returns an action object used in signalling that the block selection is cleared.
*
Expand All @@ -200,12 +211,7 @@ export function multiSelect( start, end ) {
*
* @return {Object} Action object.
*/
export function clearSelectedBlock( type = { destructive: false } ) {
if ( type.destructive === true ) {
return {
type: 'DESTRUCTIVELY_CLEAR_SELECTED_BLOCK',
};
}
export function clearSelectedBlock() {
return {
type: 'CLEAR_SELECTED_BLOCK',
};
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ const BLOCK_SELECTION_INITIAL_STATE = {
*/
export function blockSelection( state = BLOCK_SELECTION_INITIAL_STATE, action ) {
switch ( action.type ) {
case 'DESTRUCTIVELY_CLEAR_SELECTED_BLOCK':
case 'WIPE_SELECTED_BLOCK':
return BLOCK_SELECTION_INITIAL_STATE;
case 'CLEAR_SELECTED_BLOCK':
if ( isEqual( state, 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( { destructive: true } );
dispatch( 'core/block-editor' ).wipeSelectedBlock();
}

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

0 comments on commit 5709b2f

Please sign in to comment.