Skip to content

Commit

Permalink
Text Block: When splitting a text block, avoid empty paragraphs at th…
Browse files Browse the repository at this point in the history
…e begining of the created block (#553)
  • Loading branch information
youknowriad committed Apr 28, 2017
1 parent efba3db commit 92be486
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions blocks/components/editable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,19 @@ export default class Editable extends wp.element.Component {
}
const before = getHtml( 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 = getHtml( 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 hasAfter = !! childNodes.slice( splitIndex )
.reduce( ( memo, node ) => memo + node.textContent, '' );

const after = hasAfter ? getHtml( childNodes.slice( splitIndex ) ) : '';

// The setTimeout fixes the focus jump to the original block
setTimeout( () => {
Expand Down

0 comments on commit 92be486

Please sign in to comment.