Skip to content

Commit

Permalink
Check if Enter.key is the last inserted character, and add a new defa…
Browse files Browse the repository at this point in the history
…ult block after the current More block. (#12639)

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 wordpress-mobile/gutenberg-mobile#324
  • Loading branch information
daniloercoli committed Dec 6, 2018
1 parent 5ca5479 commit b9e9afd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/block-library/src/more/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: '',
Expand Down

0 comments on commit b9e9afd

Please sign in to comment.