diff --git a/gutenberg b/gutenberg index 8c91964c6a..aa791feb9a 160000 --- a/gutenberg +++ b/gutenberg @@ -1 +1 @@ -Subproject commit 8c91964c6a47cbc4d57152c48a8ef7091048265e +Subproject commit aa791feb9aa9a5e3d4d57c7476f985cc5b934762 diff --git a/src/block-management/block-holder.js b/src/block-management/block-holder.js index b5ba888cd3..e5b1330d31 100644 --- a/src/block-management/block-holder.js +++ b/src/block-management/block-holder.js @@ -19,6 +19,7 @@ type PropsType = BlockType & { onChange: ( clientId: string, attributes: mixed ) => void, onToolbarButtonPressed: ( button: number, clientId: string ) => void, onBlockHolderPressed: ( clientId: string ) => void, + insertBlocksAfter: ( blocks: Array ) => void, }; type StateType = { @@ -69,6 +70,7 @@ export default class BlockHolder extends React.Component { setAttributes={ ( attrs ) => this.props.onChange( this.props.clientId, { ...this.props.attributes, ...attrs } ) } + insertBlocksAfter={ this.props.insertBlocksAfter } isSelected={ this.props.focused } style={ style } /> diff --git a/src/block-management/block-manager.js b/src/block-management/block-manager.js index 70d68d506c..08f6d905b9 100644 --- a/src/block-management/block-manager.js +++ b/src/block-management/block-manager.js @@ -139,6 +139,21 @@ export default class BlockManager extends React.Component this.state.dataSource.setDirty(); } + insertBlocksAfter( clientId: string, blocks: Array ) { + // find currently focused block + const focusedItemIndex = this.getDataSourceIndexFromClientId( clientId ); + + const newBlock = blocks[ 0 ]; + newBlock.focused = true; + + // set it into the datasource, and use the same object instance to send it to props/redux + this.state.dataSource.splice( focusedItemIndex + 1, 0, newBlock ); + this.props.createBlockAction( newBlock.clientId, newBlock, clientId ); + + // now set the focus + this.props.focusBlockAction( newBlock.clientId ); // this not working atm + } + onChange( clientId: string, attributes: mixed ) { // Update Redux store this.props.onChange( clientId, attributes ); @@ -252,6 +267,9 @@ export default class BlockManager extends React.Component showTitle={ this.state.inspectBlocks } focused={ value.item.focused } clientId={ value.clientId } + insertBlocksAfter={ ( blocks ) => + this.insertBlocksAfter.bind( this )( value.item.clientId, blocks ) + } { ...value.item } /> { this.state.blockTypePickerVisible && value.item.focused && insertHere }