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] Split Para/Heading blocks on enter.KEY - step 1 #10553

Merged
merged 7 commits into from
Oct 16, 2018
22 changes: 21 additions & 1 deletion packages/block-library/src/heading/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { View } from 'react-native';
import { __ } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import { RichText } from '@wordpress/editor';
import { parse } from '@wordpress/blocks';
import { parse, createBlock } from '@wordpress/blocks';

/**
* Internal dependencies
Expand All @@ -24,6 +24,25 @@ import './editor.scss';
const minHeight = 50;

class HeadingEdit extends Component {
constructor() {
super( ...arguments );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: can we remove this extra line here?

this.splitBlock = this.splitBlock.bind( this );
}

// eslint-disable-next-line no-unused-vars
splitBlock( htmlText, start, end ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daniloercoli , can we perhaps go closer to the interface of the web-side counterpart, wdyt? https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/heading/edit.js#L52.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, we will probably go toward that direction in the short future. For now i'd like to go with the current implementation, and get the ball rolling.

const {
insertBlocksAfter,
} = this.props;

if ( insertBlocksAfter ) {
const blocks = [];
blocks.push( createBlock( 'core/paragraph', { content: 'Test' } ) );
insertBlocksAfter( blocks );
}
}

render() {
const {
attributes,
Expand Down Expand Up @@ -55,6 +74,7 @@ class HeadingEdit extends Component {
content: newParaBlock.attributes.content,
} );
} }
onSplit={ this.splitBlock }
onContentSizeChange={ ( event ) => {
setAttributes( { aztecHeight: event.aztecHeight } );
} }
Expand Down
22 changes: 21 additions & 1 deletion packages/block-library/src/paragraph/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,31 @@ import { View } from 'react-native';
*/
import { __ } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import { parse } from '@wordpress/blocks';
import { parse, createBlock } from '@wordpress/blocks';
import { RichText } from '@wordpress/editor';

const minHeight = 50;

class ParagraphEdit extends Component {
constructor() {
super( ...arguments );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick #3: let's remove the extra line here

this.splitBlock = this.splitBlock.bind( this );
}

// eslint-disable-next-line no-unused-vars
splitBlock( htmlText, start, end ) {
const {
insertBlocksAfter,
} = this.props;

if ( insertBlocksAfter ) {
const blocks = [];
blocks.push( createBlock( 'core/paragraph', { content: 'Test' } ) );
insertBlocksAfter( blocks );
}
}

render() {
const {
attributes,
Expand Down Expand Up @@ -44,6 +63,7 @@ class ParagraphEdit extends Component {
} );
}
}
onSplit={ this.splitBlock }
onContentSizeChange={ ( event ) => {
setAttributes( {
...this.props.attributes,
Expand Down
18 changes: 16 additions & 2 deletions packages/editor/src/components/rich-text/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,22 @@ export class RichText extends Component {
}

// eslint-disable-next-line no-unused-vars
onHTMLContentWithCursor( htmlText, cursorPosition ) {
// Descriptive placeholder: This logic still needs to be implemented.
onHTMLContentWithCursor( htmlText, start, end ) {
if ( ! this.props.onSplit ) {
// insert the \n char instead?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a ToDo comment here to make sure this is something we come back to at a follow up stage

return;
}
this.splitContent( htmlText, start, end );
}

splitContent( htmlText, start, end ) {
const { onSplit } = this.props;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick #2: can we remove this extra line here?

if ( ! onSplit ) {
return;
}

onSplit( htmlText, start, end );
}

onActiveFormatsChange( formats ) {
Expand Down