Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RNMobile] Add Enter.key detection to More blocks #12639

Merged
merged 1 commit into from
Dec 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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