Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't automatically select blocks when entering zoom out #61433

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove only this branch

}
}
} 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this branch.

const lastRootBlock = allBlocks[ allBlocks.length - 1 ];
dispatch.selectBlock( lastRootBlock?.clientId );
}
}

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

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