Skip to content

Commit

Permalink
Inserter: Fix the insertion point when using the inserter
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Aug 29, 2017
1 parent 5b5048f commit 14574e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions editor/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ export default connect(
};
},
( dispatch ) => ( {
onInsertBlock( name, after ) {
onInsertBlock( name, position ) {
dispatch( hideInsertionPoint() );
dispatch( insertBlock(
createBlock( name ),
after
position
) );
},
} )
Expand Down
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 @@ -215,12 +215,11 @@ class VisualEditorBlockList extends Component {
insertionPoint,
} = this.props;

const insertionPointIndex = blocks.indexOf( insertionPoint );
const blocksWithInsertionPoint = showInsertionPoint
? [
...blocks.slice( 0, insertionPointIndex + 1 ),
...blocks.slice( 0, insertionPoint ),
INSERTION_POINT_PLACEHOLDER,
...blocks.slice( insertionPointIndex + 1 ),
...blocks.slice( insertionPoint ),
]
: blocks;
const continueWritingClassname = classnames( 'editor-visual-editor__continue-writing', {
Expand Down
13 changes: 6 additions & 7 deletions editor/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,29 +666,28 @@ export function isTyping( state ) {
}

/**
* Returns the unique ID of the block after which a new block insertion would
* be placed, or null if the insertion point is not shown. Defaults to the
* unique ID of the last block occurring in the post if not otherwise assigned.
* Returns the insertion point, the index at which the new inserted block would
* be placed. Defaults to the last position
*
* @param {Object} state Global application state
* @return {?String} Unique ID after which insertion will occur
*/
export function getBlockInsertionPoint( state ) {
if ( getEditorMode( state ) !== 'visual' ) {
return last( state.editor.blockOrder );
return state.editor.blockOrder.length;
}

const lastMultiSelectedBlock = getLastMultiSelectedBlockUid( state );
if ( lastMultiSelectedBlock ) {
return lastMultiSelectedBlock;
return getBlockIndex( state, lastMultiSelectedBlock ) + 1;
}

const selectedBlock = getSelectedBlock( state );
if ( selectedBlock ) {
return selectedBlock.uid;
return getBlockIndex( state, selectedBlock.uid ) + 1;
}

return last( state.editor.blockOrder );
return state.editor.blockOrder.length;
}

/**
Expand Down

0 comments on commit 14574e7

Please sign in to comment.