Skip to content

Commit

Permalink
De-duplicate block toolbar icons for patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Sep 4, 2024
1 parent 2807adb commit c864b26
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export function PrivateBlockToolbar( {
shouldShowVisualToolbar,
showParentSelector,
isUsingBindings,
hasParentPattern,
} = useSelect( ( select ) => {
const {
getBlockName,
Expand All @@ -74,6 +75,7 @@ export function PrivateBlockToolbar( {
isBlockValid,
getBlockEditingMode,
getBlockAttributes,
getBlockParentsByBlockName,
} = select( blockEditorStore );
const selectedBlockClientIds = getSelectedBlockClientIds();
const selectedBlockClientId = selectedBlockClientIds[ 0 ];
Expand All @@ -94,6 +96,13 @@ export function PrivateBlockToolbar( {
( clientId ) =>
!! getBlockAttributes( clientId )?.metadata?.bindings
);

const _hasParentPattern = selectedBlockClientIds.every(
( clientId ) =>
getBlockParentsByBlockName( clientId, 'core/block', true )
.length > 0
);

return {
blockClientId: selectedBlockClientId,
blockClientIds: selectedBlockClientIds,
Expand All @@ -113,6 +122,7 @@ export function PrivateBlockToolbar( {
selectedBlockClientIds.length === 1 &&
_isDefaultEditingMode,
isUsingBindings: _isUsingBindings,
hasParentPattern: _hasParentPattern,
};
}, [] );

Expand Down Expand Up @@ -167,7 +177,7 @@ export function PrivateBlockToolbar( {
isDefaultEditingMode && <BlockParentSelector /> }
{ ( shouldShowVisualToolbar || isMultiToolbar ) &&
( isDefaultEditingMode ||
isContentOnlyEditingMode ||
( isContentOnlyEditingMode && ! hasParentPattern ) ||
isSynced ) && (
<div
ref={ nodeRef }
Expand Down

0 comments on commit c864b26

Please sign in to comment.