Skip to content

Commit

Permalink
Revert "adds selection persistence on sidebar tab switch (#15583)" (#…
Browse files Browse the repository at this point in the history
…16042)

This reverts commit 4d5998d.
  • Loading branch information
aduth authored Jun 7, 2019
1 parent 28eb941 commit 42b2748
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -824,9 +824,7 @@ _Returns_

<a name="clearSelectedBlock" href="#clearSelectedBlock">#</a> **clearSelectedBlock**

Returns an action object used in signaling that the block selection is cleared.
This will save the current selection in a state called `previousSelection` and
`restoreSelectedBlock` will be able to restore the selection.
Returns an action object used in signalling that the block selection is cleared.

_Returns_

Expand Down Expand Up @@ -1041,14 +1039,6 @@ _Returns_

- `Object`: Action object.

<a name="restoreSelectedBlock" href="#restoreSelectedBlock">#</a> **restoreSelectedBlock**

Returns an action object used in restoring the previously cleared selected blocks.

_Returns_

- `Object`: Action object.

<a name="selectBlock" href="#selectBlock">#</a> **selectBlock**

Returns an action object used in signalling that the block with the
Expand Down Expand Up @@ -1235,13 +1225,4 @@ _Returns_

Undocumented declaration.

<a name="wipeSelectedBlock" href="#wipeSelectedBlock">#</a> **wipeSelectedBlock**

Returns an action object used in signaling that the block selection is wiped.
This will remove block selection so that `restoreSelectedBlock` will have no effect.

_Returns_

- `Object`: Action object.

<!-- END TOKEN(Autogenerated actions) -->
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ class BlockSelectionClearer extends Component {
const {
hasSelectedBlock,
hasMultiSelection,
wipeSelectedBlock,
clearSelectedBlock,
} = this.props;

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

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

/**
* Returns an action object used in signaling that the block selection is wiped.
* This will remove block selection so that `restoreSelectedBlock` will have no effect.
*
* @return {Object} Action object.
*/
export function wipeSelectedBlock() {
return {
type: 'WIPE_SELECTED_BLOCK',
};
}

/**
* Returns an action object used in signaling that the block selection is cleared.
* This will save the current selection in a state called `previousSelection` and
* `restoreSelectedBlock` will be able to restore the selection.
* Returns an action object used in signalling that the block selection is cleared.
*
* @return {Object} Action object.
*/
Expand All @@ -217,17 +203,6 @@ export function clearSelectedBlock() {
};
}

/**
* Returns an action object used in restoring the previously cleared selected blocks.
*
* @return {Object} Action object.
*/
export function restoreSelectedBlock() {
return {
type: 'RESTORE_SELECTED_BLOCK',
};
}

/**
* Returns an action object that enables or disables block selection.
*
Expand Down
15 changes: 1 addition & 14 deletions packages/block-editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,21 +717,8 @@ const BLOCK_SELECTION_INITIAL_STATE = {
*/
export function blockSelection( state = BLOCK_SELECTION_INITIAL_STATE, action ) {
switch ( action.type ) {
case 'WIPE_SELECTED_BLOCK':
return BLOCK_SELECTION_INITIAL_STATE;
case 'CLEAR_SELECTED_BLOCK':
if ( isEqual( state, BLOCK_SELECTION_INITIAL_STATE ) ) {
return BLOCK_SELECTION_INITIAL_STATE;
}
return {
...BLOCK_SELECTION_INITIAL_STATE,
previousSelection: omit( state, [ 'previousSelection' ] ),
};
case 'RESTORE_SELECTED_BLOCK':
return {
...BLOCK_SELECTION_INITIAL_STATE,
...state.previousSelection,
};
return BLOCK_SELECTION_INITIAL_STATE;
case 'START_MULTI_SELECT':
if ( state.isMultiSelecting ) {
return state;
Expand Down
18 changes: 0 additions & 18 deletions packages/block-editor/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
*/
import {
clearSelectedBlock,
wipeSelectedBlock,
restoreSelectedBlock,
enterFormattedText,
exitFormattedText,
hideInsertionPoint,
Expand Down Expand Up @@ -118,22 +116,6 @@ describe( 'actions', () => {
} );
} );

describe( 'wipeSelectedBlock', () => {
it( 'should return WIPE_SELECTED_BLOCK action', () => {
expect( wipeSelectedBlock() ).toEqual( {
type: 'WIPE_SELECTED_BLOCK',
} );
} );
} );

describe( 'restoreSelectedBlock', () => {
it( 'should return RESTORE_SELECTED_BLOCK action', () => {
expect( restoreSelectedBlock() ).toEqual( {
type: 'RESTORE_SELECTED_BLOCK',
} );
} );
} );

describe( 'replaceBlock', () => {
it( 'should yield the REPLACE_BLOCKS action if the new block can be inserted in the destination root block', () => {
const block = {
Expand Down
1 change: 0 additions & 1 deletion packages/block-editor/src/store/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,6 @@ describe( 'state', () => {
initialPosition: null,
isMultiSelecting: false,
isEnabled: true,
previousSelection: original,
} );
} );

Expand Down
51 changes: 0 additions & 51 deletions packages/e2e-tests/specs/a11y.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* WordPress dependencies
*/
import {
clickBlockAppender,
createNewPost,
pressKeyWithModifier,
} from '@wordpress/e2e-test-utils';
Expand Down Expand Up @@ -30,56 +29,6 @@ describe( 'a11y', () => {
expect( isFocusedToggle ).toBe( true );
} );

it( 'checks persistent selection', async () => {
await clickBlockAppender();

// adding one Paragraph block which contains a focusable RichText
await page.keyboard.type( 'Testing editor selection persistence' );

let isFocusedRichText = await page.$eval( ':focus', ( focusedElement ) => {
return focusedElement.classList.contains( 'block-editor-rich-text__editable' );
} );

expect( isFocusedRichText ).toBe( true );

// moving focus backwards using keyboard shortcuts
// twice to get to the inspector tabs
await pressKeyWithModifier( 'ctrlShift', '`' );
await pressKeyWithModifier( 'ctrlShift', '`' );

await page.keyboard.press( 'Tab' );

const isFocusedInspectorDocumentTab = await page.$eval( ':focus', ( focusedElement ) => {
return focusedElement.getAttribute( 'data-label' );
} );

expect( isFocusedInspectorDocumentTab ).toEqual( 'Document' );

await page.keyboard.press( 'Space' );

isFocusedRichText = await page.$eval( ':focus', ( focusedElement ) => {
return focusedElement.classList.contains( 'block-editor-rich-text__editable' );
} );

expect( isFocusedRichText ).toBe( false );

await page.keyboard.press( 'Tab' );

const isFocusedInspectorBlockTab = await page.$eval( ':focus', ( focusedElement ) => {
return focusedElement.getAttribute( 'data-label' );
} );

expect( isFocusedInspectorBlockTab ).toEqual( 'Block' );

await page.keyboard.press( 'Space' );

isFocusedRichText = await page.$eval( ':focus', ( focusedElement ) => {
return focusedElement.classList.contains( 'block-editor-rich-text__editable' );
} );

expect( isFocusedRichText ).toBe( true );
} );

it( 'constrains focus to a modal when tabbing', async () => {
// Open keyboard help modal.
await pressKeyWithModifier( 'access', 'h' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,14 @@ const SettingsHeader = ( { openDocumentSettings, openBlockSettings, sidebarName

export default withDispatch( ( dispatch ) => {
const { openGeneralSidebar } = dispatch( 'core/edit-post' );
const { clearSelectedBlock, restoreSelectedBlock } = dispatch( 'core/block-editor' );

const { clearSelectedBlock } = dispatch( 'core/block-editor' );
return {
openDocumentSettings() {
openGeneralSidebar( 'edit-post/document' );
clearSelectedBlock();
},
openBlockSettings() {
openGeneralSidebar( 'edit-post/block' );
restoreSelectedBlock();
},
};
} )( SettingsHeader );
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' ).wipeSelectedBlock();
dispatch( 'core/block-editor' ).clearSelectedBlock();
}

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

0 comments on commit 42b2748

Please sign in to comment.