Skip to content

Commit

Permalink
Rich Text: Remove NewBlock event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Jun 28, 2018
1 parent 248697a commit 713ffc5
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 @@ -110,7 +109,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.onKeyDown = this.onKeyDown.bind( this );
this.onKeyUp = this.onKeyUp.bind( this );
Expand Down Expand Up @@ -159,7 +157,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 @@ -610,55 +607,6 @@ export class RichText extends Component {
}
}

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 713ffc5

Please sign in to comment.