diff --git a/editor/components/rich-text/index.js b/editor/components/rich-text/index.js index 0d12d2dcd646b..50005fafdcd00 100644 --- a/editor/components/rich-text/index.js +++ b/editor/components/rich-text/index.js @@ -3,7 +3,6 @@ */ import classnames from 'classnames'; import { - last, isEqual, forEach, merge, @@ -126,7 +125,6 @@ export class RichText extends Component { this.onSetup = this.onSetup.bind( this ); this.onFocus = this.onFocus.bind( this ); this.onChange = this.onChange.bind( this ); - this.onNewBlock = this.onNewBlock.bind( this ); this.onNodeChange = this.onNodeChange.bind( this ); this.onHorizontalNavigationKeyDown = this.onHorizontalNavigationKeyDown.bind( this ); this.onKeyDown = this.onKeyDown.bind( this ); @@ -176,7 +174,6 @@ export class RichText extends Component { this.editor = editor; editor.on( 'init', this.onInit ); - editor.on( 'NewBlock', this.onNewBlock ); editor.on( 'nodechange', this.onNodeChange ); editor.on( 'keydown', this.onKeyDown ); editor.on( 'keyup', this.onKeyUp ); @@ -667,55 +664,6 @@ export class RichText extends Component { this.restoreContentAndSplit( before, after, blocks ); } - onNewBlock() { - if ( this.props.multiline !== 'p' || ! this.props.onSplit ) { - return; - } - - // Getting the content before and after the cursor - const childNodes = Array.from( this.editor.getBody().childNodes ); - let selectedChild = this.editor.selection.getStart(); - while ( childNodes.indexOf( selectedChild ) === -1 && selectedChild.parentNode ) { - selectedChild = selectedChild.parentNode; - } - const splitIndex = childNodes.indexOf( selectedChild ); - if ( splitIndex === -1 ) { - return; - } - const beforeNodes = childNodes.slice( 0, splitIndex ); - const lastNodeBeforeCursor = last( beforeNodes ); - // Avoid splitting on single enter - if ( - ! lastNodeBeforeCursor || - beforeNodes.length < 2 || - !! lastNodeBeforeCursor.textContent - ) { - return; - } - - const before = beforeNodes.slice( 0, beforeNodes.length - 1 ); - - // Removing empty nodes from the beginning of the "after" - // avoids empty paragraphs at the beginning of newly created blocks. - const after = childNodes.slice( splitIndex ).reduce( ( memo, node ) => { - if ( ! memo.length && ! node.textContent ) { - return memo; - } - - memo.push( node ); - return memo; - }, [] ); - - // Splitting into two blocks - this.setContent( this.props.value ); - - const { format } = this.props; - this.restoreContentAndSplit( - domToFormat( before, format, this.editor ), - domToFormat( after, format, this.editor ) - ); - } - onNodeChange( { parents } ) { if ( document.activeElement !== this.editor.getBody() ) { return;