Skip to content

Commit

Permalink
Rich Text: Remove NewBlock event handling (#7617)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth authored Jul 10, 2018
1 parent 86c2d1e commit d574792
Showing 1 changed file with 0 additions and 52 deletions.
52 changes: 0 additions & 52 deletions editor/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import classnames from 'classnames';
import {
last,
isEqual,
forEach,
merge,
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d574792

Please sign in to comment.