Skip to content

Commit

Permalink
VisualEditorSiblingInserter: Don't require insertIndex from parent
Browse files Browse the repository at this point in the history
  • Loading branch information
mcsf committed Nov 15, 2017
1 parent f4d6ebf commit b3218c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 2 additions & 3 deletions editor/modes/visual-editor/block-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ class VisualEditorBlockList extends Component {

return (
<div>
{ !! blocks.length && <VisualEditorSiblingInserter insertIndex={ 0 } /> }
{ flatMap( blocks, ( uid, index ) => [
{ !! blocks.length && <VisualEditorSiblingInserter /> }
{ flatMap( blocks, ( uid ) => [
<VisualEditorBlock
key={ 'block-' + uid }
uid={ uid }
Expand All @@ -221,7 +221,6 @@ class VisualEditorBlockList extends Component {
<VisualEditorSiblingInserter
key={ 'sibling-inserter-' + uid }
uid={ uid }
insertIndex={ index + 1 }
/>,
] ) }
{ ! blocks.length &&
Expand Down
11 changes: 8 additions & 3 deletions editor/modes/visual-editor/sibling-inserter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { focus } from '@wordpress/utils';
*/
import { Inserter } from '../../components';
import {
getBlockUids,
getBlockInsertionPoint,
isBlockInsertionPointVisible,
isBlockWithinSelection,
Expand Down Expand Up @@ -126,12 +127,16 @@ class VisualEditorSiblingInserter extends Component {
}

export default connect(
( state, ownProps ) => {
( state, { uid } ) => {
const blockIndex = uid ? getBlockUids( state ).indexOf( uid ) : -1;
const insertIndex = blockIndex > -1 ? blockIndex + 1 : 0;

return {
shouldDisable: isBlockWithinSelection( state, ownProps.uid ),
shouldDisable: isBlockWithinSelection( state, uid ),
insertIndex,
showInsertionPoint: (
isBlockInsertionPointVisible( state ) &&
getBlockInsertionPoint( state ) === ownProps.insertIndex
getBlockInsertionPoint( state ) === insertIndex
),
};
}
Expand Down

0 comments on commit b3218c7

Please sign in to comment.