diff --git a/packages/block-editor/src/store/actions.js b/packages/block-editor/src/store/actions.js index f7da8fa14b382..319398667293e 100644 --- a/packages/block-editor/src/store/actions.js +++ b/packages/block-editor/src/store/actions.js @@ -1683,11 +1683,19 @@ export const __unstableSetEditorMode = if ( sectionRootClientId ) { const sectionClientIds = select.getBlockOrder( sectionRootClientId ); - sectionClientId = select - .getBlockParents( firstSelectedClientId ) - .find( ( parent ) => - sectionClientIds.includes( parent ) - ); + + // If the selected block is a section block, use it. + if ( sectionClientIds?.includes( firstSelectedClientId ) ) { + sectionClientId = firstSelectedClientId; + } else { + // If the selected block is not a section block, find + // the parent section that contains the selected block. + sectionClientId = select + .getBlockParents( firstSelectedClientId ) + .find( ( parent ) => + sectionClientIds.includes( parent ) + ); + } } else { sectionClientId = select.getBlockHierarchyRootClientId( firstSelectedClientId