diff --git a/packages/block-library/src/heading/edit.native.js b/packages/block-library/src/heading/edit.native.js index fba00e8c6f15ba..3d84600da25fde 100644 --- a/packages/block-library/src/heading/edit.native.js +++ b/packages/block-library/src/heading/edit.native.js @@ -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 @@ -24,6 +24,24 @@ import './editor.scss'; const minHeight = 50; class HeadingEdit extends Component { + constructor() { + super( ...arguments ); + 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, @@ -55,6 +73,7 @@ class HeadingEdit extends Component { content: newParaBlock.attributes.content, } ); } } + onSplit={ this.splitBlock } onContentSizeChange={ ( event ) => { setAttributes( { aztecHeight: event.aztecHeight } ); } } diff --git a/packages/block-library/src/paragraph/edit.native.js b/packages/block-library/src/paragraph/edit.native.js index 9b6975cbf8e929..1b35bf84a1088f 100644 --- a/packages/block-library/src/paragraph/edit.native.js +++ b/packages/block-library/src/paragraph/edit.native.js @@ -8,12 +8,30 @@ 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 ); + 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, @@ -44,6 +62,7 @@ class ParagraphEdit extends Component { } ); } } + onSplit={ this.splitBlock } onContentSizeChange={ ( event ) => { setAttributes( { ...this.props.attributes, diff --git a/packages/editor/src/components/rich-text/index.native.js b/packages/editor/src/components/rich-text/index.native.js index e2715369f7cdbc..71d13f67761c21 100644 --- a/packages/editor/src/components/rich-text/index.native.js +++ b/packages/editor/src/components/rich-text/index.native.js @@ -48,8 +48,20 @@ 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 ) { + // TODO: insert the \n char instead? + return; + } + this.splitContent( htmlText, start, end ); + } + + splitContent( htmlText, start, end ) { + const { onSplit } = this.props; + if ( ! onSplit ) { + return; + } + onSplit( htmlText, start, end ); } onActiveFormatsChange( formats ) {