From 4b1becd0b8bf4e87293ebcc001a37875ea8906bc Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Sun, 2 Jun 2019 15:01:03 +0300 Subject: [PATCH] adds destructive selection clearer and clears on visual edititng toggle and manual deselection --- .../block-selection-clearer/index.js | 8 ++++---- packages/block-editor/src/store/actions.js | 18 ++++++++++++------ packages/block-editor/src/store/reducer.js | 2 +- packages/edit-post/src/store/effects.js | 2 +- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/block-editor/src/components/block-selection-clearer/index.js b/packages/block-editor/src/components/block-selection-clearer/index.js index be39e5df9e7de..cc2e27944e06b 100644 --- a/packages/block-editor/src/components/block-selection-clearer/index.js +++ b/packages/block-editor/src/components/block-selection-clearer/index.js @@ -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(); } } @@ -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 ); diff --git a/packages/block-editor/src/store/actions.js b/packages/block-editor/src/store/actions.js index bd18f39fff12e..9361e62c1c70f 100644 --- a/packages/block-editor/src/store/actions.js +++ b/packages/block-editor/src/store/actions.js @@ -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. * @@ -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', }; diff --git a/packages/block-editor/src/store/reducer.js b/packages/block-editor/src/store/reducer.js index 3bf5b24022907..e62734d0412e2 100644 --- a/packages/block-editor/src/store/reducer.js +++ b/packages/block-editor/src/store/reducer.js @@ -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 ) ) { diff --git a/packages/edit-post/src/store/effects.js b/packages/edit-post/src/store/effects.js index 2b747431250a8..36d3c2b501369 100644 --- a/packages/edit-post/src/store/effects.js +++ b/packages/edit-post/src/store/effects.js @@ -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' );