From 20d82de21b93e233efb6c939beaec515480921c1 Mon Sep 17 00:00:00 2001 From: Jorge Date: Tue, 10 Jul 2018 18:06:36 +0100 Subject: [PATCH] Sibling Inserter: Hide insertion point if it is not possible to insert the default block (#7226) Fixes part of https://github.com/WordPress/gutenberg/issues/6569. Part of a general polishing to get #6993. Insertion point was violating the allowedBlocks restriction of the parent block. The insertion point always inserts the default block and it may not be possible to insert the default block. This PR makes sure insertion point only appears if it is possible to insert the default block. --- editor/components/block-list/insertion-point.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/editor/components/block-list/insertion-point.js b/editor/components/block-list/insertion-point.js index eedc670a7abea7..d39167607687b7 100644 --- a/editor/components/block-list/insertion-point.js +++ b/editor/components/block-list/insertion-point.js @@ -76,13 +76,16 @@ class BlockInsertionPoint extends Component { export default compose( withSelect( ( select, { uid, rootUID, canShowInserter } ) => { const { + canInsertBlockType, getBlockIndex, getBlockInsertionPoint, getBlock, isBlockInsertionPointVisible, isTyping, - getTemplateLock, } = select( 'core/editor' ); + const { + getDefaultBlockName, + } = select( 'core/blocks' ); const blockIndex = uid ? getBlockIndex( uid, rootUID ) : -1; const insertIndex = blockIndex; const insertionPoint = getBlockInsertionPoint(); @@ -94,14 +97,15 @@ export default compose( ( ! block || ! isUnmodifiedDefaultBlock( block ) ) ); + const defaultBlockName = getDefaultBlockName(); return { - isLocked: !! getTemplateLock( insertionPoint.rootUID ), + canInsertDefaultBlock: canInsertBlockType( defaultBlockName, rootUID ), showInserter: ! isTyping() && canShowInserter, index: insertIndex, showInsertionPoint, }; } ), - ifCondition( ( { isLocked } ) => ! isLocked ), + ifCondition( ( { canInsertDefaultBlock } ) => canInsertDefaultBlock ), withDispatch( ( dispatch ) => { const { insertDefaultBlock, startTyping } = dispatch( 'core/editor' ); return {