Skip to content

Commit

Permalink
Sibling Inserter: Hide insertion point if it is not possible to inser…
Browse files Browse the repository at this point in the history
…t the default block (#7226)

Fixes part of #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.
  • Loading branch information
jorgefilipecosta authored Jul 10, 2018
1 parent 7a878e0 commit 20d82de
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions editor/components/block-list/insertion-point.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 {
Expand Down

0 comments on commit 20d82de

Please sign in to comment.