From 14d482bbf2414a521cd2138c369c001f1b529483 Mon Sep 17 00:00:00 2001 From: Matt Chowning Date: Tue, 6 Aug 2019 17:04:35 -0400 Subject: [PATCH] [RNMobile] Insure tapping at end of post inserts at end Previously, tapping at the end of the post would insert a block immediately after the currently selected block. In addition, this commit is cleaning out a few unusued props in the block-list file. --- .../src/components/block-list/index.native.js | 32 +++---------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/packages/block-editor/src/components/block-list/index.native.js b/packages/block-editor/src/components/block-list/index.native.js index 5a78753c1249bc..a2e7fbf9511479 100644 --- a/packages/block-editor/src/components/block-list/index.native.js +++ b/packages/block-editor/src/components/block-list/index.native.js @@ -33,31 +33,12 @@ export class BlockList extends Component { this.renderDefaultBlockAppender = this.renderDefaultBlockAppender.bind( this ); this.onCaretVerticalPositionChange = this.onCaretVerticalPositionChange.bind( this ); this.scrollViewInnerRef = this.scrollViewInnerRef.bind( this ); - this.getNewBlockInsertionIndex = this.getNewBlockInsertionIndex.bind( this ); + this.addBlockToEndOfPost = this.addBlockToEndOfPost.bind( this ); this.shouldFlatListPreventAutomaticScroll = this.shouldFlatListPreventAutomaticScroll.bind( this ); } - finishBlockAppendingOrReplacing( newBlock ) { - // now determine whether we need to replace the currently selected block (if it's empty) - // or just add a new block as usual - if ( this.isReplaceable( this.props.selectedBlock ) ) { - // do replace here - this.props.replaceBlock( this.props.selectedBlockClientId, newBlock ); - } else { - this.props.insertBlock( newBlock, this.getNewBlockInsertionIndex() ); - } - } - - getNewBlockInsertionIndex() { - if ( this.props.isPostTitleSelected ) { - // if post title selected, insert at top of post - return 0; - } else if ( this.props.selectedBlockIndex === -1 ) { - // if no block selected, insert at end of post - return this.props.blockCount; - } - // insert after selected block - return this.props.selectedBlockIndex + 1; + addBlockToEndOfPost( newBlock ) { + this.props.insertBlock( newBlock, this.props.blockCount ); } blockHolderBorderStyle() { @@ -162,7 +143,7 @@ export class BlockList extends Component { const paragraphBlock = createBlock( 'core/paragraph' ); return ( { - this.finishBlockAppendingOrReplacing( paragraphBlock ); + this.addBlockToEndOfPost( paragraphBlock ); } } > @@ -174,10 +155,8 @@ export default compose( [ withSelect( ( select, { rootClientId } ) => { const { getBlockCount, - getBlockName, getBlockIndex, getBlockOrder, - getSelectedBlock, getSelectedBlockClientId, getBlockInsertionPoint, isBlockInsertionPointVisible, @@ -210,13 +189,10 @@ export default compose( [ return { blockClientIds, blockCount: getBlockCount( rootClientId ), - getBlockName, isBlockInsertionPointVisible: isBlockInsertionPointVisible(), shouldShowBlockAtIndex, shouldShowInsertionPoint, - selectedBlock: getSelectedBlock(), selectedBlockClientId, - selectedBlockIndex, }; } ), withDispatch( ( dispatch ) => {