From 344b625055735c43e53777c6804d108d6be6d393 Mon Sep 17 00:00:00 2001 From: Danilo Ercoli Date: Thu, 6 Dec 2018 11:34:16 +0100 Subject: [PATCH] Check if Enter.key is the last inserted character, and add a new default block after the current More block. Note: This is detected after the fact, and the newline could be visible on the block for a very small time. This is OK for the alpha, we will revisit the logic later. See https://github.com/wordpress-mobile/gutenberg-mobile/issues/324 --- packages/block-library/src/more/edit.native.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/block-library/src/more/edit.native.js b/packages/block-library/src/more/edit.native.js index 36dc0495f8c8d..a6845e2ade8a5 100644 --- a/packages/block-library/src/more/edit.native.js +++ b/packages/block-library/src/more/edit.native.js @@ -8,6 +8,10 @@ import { View, Text } from 'react-native'; */ import { __ } from '@wordpress/i18n'; import { Component } from '@wordpress/element'; +import { + getDefaultBlockName, + createBlock, +} from '@wordpress/blocks'; /** * Internal dependencies @@ -26,6 +30,15 @@ export default class MoreEdit extends Component { } onChangeInput( newValue ) { + // Detect Enter.key and add new empty block after. + // Note: This is detected after the fact, and the newline could be visible on the block + // for a very small time. This is OK for the alpha, we will revisit the logic later. + // See https://github.com/wordpress-mobile/gutenberg-mobile/issues/324 + if ( newValue.indexOf( '\n' ) !== -1 ) { + const { insertBlocksAfter } = this.props; + insertBlocksAfter( [ createBlock( getDefaultBlockName() ) ] ); + return; + } // Set defaultText to an empty string, allowing the user to clear/replace the input field's text this.setState( { defaultText: '',