Skip to content

Commit 8a109fb

Browse files
committed
Block Inspector and Block Switcher: Refactor section block detection to improve handling of multiple selected blocks, ensuring accurate identification of section blocks in selection.
1 parent 5bd9f06 commit 8a109fb

File tree

2 files changed

+12
-9
lines changed
  • packages/block-editor/src/components

2 files changed

+12
-9
lines changed

packages/block-editor/src/components/block-inspector/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function BlockInspector() {
4747
selectedBlockClientId,
4848
blockType,
4949
isSectionBlock,
50+
isSectionBlockInSelection,
5051
} = useSelect( ( select ) => {
5152
const {
5253
getSelectedBlockClientId,
@@ -65,16 +66,17 @@ function BlockInspector() {
6566
const _blockType =
6667
_selectedBlockName && getBlockType( _selectedBlockName );
6768
const selectedBlockClientIds = getSelectedBlockClientIds();
68-
const isSectionInSelection = selectedBlockClientIds.some( ( id ) =>
69-
_isSectionBlock( id )
69+
const _isSectionBlockInSelection = selectedBlockClientIds.some(
70+
( id ) => _isSectionBlock( id )
7071
);
7172

7273
return {
7374
count: getSelectedBlockCount(),
7475
selectedBlockClientId: renderedBlockClientId,
7576
selectedBlockName: _selectedBlockName,
7677
blockType: _blockType,
77-
isSectionBlock: isSectionInSelection,
78+
isSectionBlockInSelection: _isSectionBlockInSelection,
79+
isSectionBlock: _isSectionBlock( renderedBlockClientId ),
7880
};
7981
}, [] );
8082

@@ -96,7 +98,7 @@ function BlockInspector() {
9698

9799
const hasSelectedBlocks = count > 1;
98100

99-
if ( hasSelectedBlocks && ! isSectionBlock ) {
101+
if ( hasSelectedBlocks && ! isSectionBlockInSelection ) {
100102
return (
101103
<div className="block-editor-block-inspector">
102104
<MultiSelectionInspector />
@@ -133,7 +135,7 @@ function BlockInspector() {
133135
);
134136
}
135137

136-
if ( hasSelectedBlocks && isSectionBlock ) {
138+
if ( hasSelectedBlocks && isSectionBlockInSelection ) {
137139
return (
138140
<div className="block-editor-block-inspector">
139141
<MultiSelectionInspector />

packages/block-editor/src/components/block-switcher/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export const BlockSwitcher = ( { clientIds } ) => {
199199
isReusable,
200200
isTemplate,
201201
isDisabled,
202-
isSection,
202+
isSectionInSelection,
203203
} = useSelect(
204204
( select ) => {
205205
const {
@@ -243,7 +243,7 @@ export const BlockSwitcher = ( { clientIds } ) => {
243243
_icon = isSelectionOfSameType ? blockType.icon : copy;
244244
}
245245

246-
const isSectionInSelection = clientIds.some( ( id ) =>
246+
const _isSectionInSelection = clientIds.some( ( id ) =>
247247
isSectionBlock( id )
248248
);
249249

@@ -259,7 +259,7 @@ export const BlockSwitcher = ( { clientIds } ) => {
259259
_isSingleBlockSelected && isTemplatePart( _blocks[ 0 ] ),
260260
hasContentOnlyLocking: _hasTemplateLock,
261261
isDisabled: editingMode !== 'default',
262-
isSection: isSectionInSelection,
262+
isSectionInSelection: _isSectionInSelection,
263263
};
264264
},
265265
[ clientIds ]
@@ -289,7 +289,8 @@ export const BlockSwitcher = ( { clientIds } ) => {
289289
: undefined;
290290

291291
const hideTransformsForSections =
292-
window?.__experimentalContentOnlyPatternInsertion && isSection;
292+
window?.__experimentalContentOnlyPatternInsertion &&
293+
isSectionInSelection;
293294
const hideDropdown =
294295
hideTransformsForSections ||
295296
isDisabled ||

0 commit comments

Comments
 (0)