Skip to content

Commit

Permalink
[RNMobile] Insure tapping at end of post inserts at end
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mchowning committed Aug 30, 2019
1 parent 7b12673 commit 14d482b
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions packages/block-editor/src/components/block-list/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -162,7 +143,7 @@ export class BlockList extends Component {
const paragraphBlock = createBlock( 'core/paragraph' );
return (
<TouchableWithoutFeedback onPress={ () => {
this.finishBlockAppendingOrReplacing( paragraphBlock );
this.addBlockToEndOfPost( paragraphBlock );
} } >
<View style={ styles.blockListFooter } />
</TouchableWithoutFeedback>
Expand All @@ -174,10 +155,8 @@ export default compose( [
withSelect( ( select, { rootClientId } ) => {
const {
getBlockCount,
getBlockName,
getBlockIndex,
getBlockOrder,
getSelectedBlock,
getSelectedBlockClientId,
getBlockInsertionPoint,
isBlockInsertionPointVisible,
Expand Down Expand Up @@ -210,13 +189,10 @@ export default compose( [
return {
blockClientIds,
blockCount: getBlockCount( rootClientId ),
getBlockName,
isBlockInsertionPointVisible: isBlockInsertionPointVisible(),
shouldShowBlockAtIndex,
shouldShowInsertionPoint,
selectedBlock: getSelectedBlock(),
selectedBlockClientId,
selectedBlockIndex,
};
} ),
withDispatch( ( dispatch ) => {
Expand Down

0 comments on commit 14d482b

Please sign in to comment.