Skip to content

Commit

Permalink
See what happens when we don't select blocks when entering zoom out mode
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed May 7, 2024
1 parent 8bf83c9 commit 1e32b15
Showing 1 changed file with 1 addition and 45 deletions.
46 changes: 1 addition & 45 deletions packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import {
__experimentalUpdateSettings,
privateRemoveBlocks,
} from './private-actions';
import { STORE_NAME } from './constants';
import { unlock } from '../lock-unlock';

/** @typedef {import('../components/use-on-block-drop/types').WPDropOperation} WPDropOperation */

Expand Down Expand Up @@ -1608,49 +1606,7 @@ export const setNavigationMode =
*/
export const __unstableSetEditorMode =
( mode ) =>
( { dispatch, select, registry } ) => {
// When switching to zoom-out mode, we need to select the parent section
if ( mode === 'zoom-out' ) {
const firstSelectedClientId = select.getBlockSelectionStart();
const allBlocks = select.getBlocks();

const { sectionRootClientId } = unlock(
registry.select( STORE_NAME ).getSettings()
);
if ( sectionRootClientId ) {
const sectionClientIds =
select.getBlockOrder( sectionRootClientId );
const lastSectionClientId =
sectionClientIds[ sectionClientIds.length - 1 ];
if ( sectionClientIds ) {
if ( firstSelectedClientId ) {
const parents = select.getBlockParents(
firstSelectedClientId
);
const firstSectionClientId = parents.find( ( parent ) =>
sectionClientIds.includes( parent )
);
if ( firstSectionClientId ) {
dispatch.selectBlock( firstSectionClientId );
} else {
dispatch.selectBlock( lastSectionClientId );
}
} else {
dispatch.selectBlock( lastSectionClientId );
}
}
} else if ( firstSelectedClientId ) {
const rootClientId = select.getBlockHierarchyRootClientId(
firstSelectedClientId
);
dispatch.selectBlock( rootClientId );
} else {
// If there's no block selected and no sectionRootClientId, select the last root block.
const lastRootBlock = allBlocks[ allBlocks.length - 1 ];
dispatch.selectBlock( lastRootBlock?.clientId );
}
}

( { dispatch } ) => {
dispatch( { type: 'SET_EDITOR_MODE', mode } );

if ( mode === 'navigation' ) {
Expand Down

0 comments on commit 1e32b15

Please sign in to comment.