Skip to content
Merged
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
22 changes: 15 additions & 7 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1626,15 +1626,23 @@ const isBlockVisibleInTheInserter = (
Array.isArray( blockType.parent ) ? blockType.parent : []
).concat( Array.isArray( blockType.ancestor ) ? blockType.ancestor : [] );
if ( parents.length > 0 ) {
const rootBlockName = getBlockName( state, rootClientId );
// This is an exception to the rule that says that all blocks are visible in the inserter.
// Blocks that require a given parent or ancestor are only visible if we're within that parent.
return (
parents.includes( 'core/post-content' ) ||
parents.includes( rootBlockName ) ||
getBlockParentsByBlockName( state, rootClientId, parents ).length >
0
);
if ( parents.includes( 'core/post-content' ) ) {
return true;
}

let current = rootClientId;
let hasParent = false;
do {
if ( parents.includes( getBlockName( state, current ) ) ) {
hasParent = true;
break;
}
current = state.blocks.parents.get( current );
} while ( current );

return hasParent;
}

return true;
Expand Down
Loading