Skip to content

Commit

Permalink
Re-order onReplace and insertBlocksAfter for heading unstableOnSplit
Browse files Browse the repository at this point in the history
Since my last commit, the behaviour of onReplace seems to have changed a little bit. This commit ensures that an empty paragraph is added before a heading if a heading is 'split' with no before text, but with some after text (e.g. if the carat is at the beginning of a heading and the user presses ENTER)

Also removed unnecessary `event.stopImmediatePropagation()`.
  • Loading branch information
andrewserong committed Feb 13, 2019
1 parent 91daa21 commit be995ca
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
8 changes: 4 additions & 4 deletions packages/block-library/src/heading/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ export default function HeadingEdit( {
insertBlocksAfter ?
( before, after, ...blocks ) => {
setAttributes( { content: before } );
if ( ! before.text && after.text ) {
onReplace( createBlock( 'core/paragraph', { content: before } ) );
}
if ( after.text ) {
if ( after ) {
insertBlocksAfter( [
...blocks,
createBlock( 'core/heading', { content: after } ),
Expand All @@ -66,6 +63,9 @@ export default function HeadingEdit( {
createBlock( 'core/paragraph', { content: after } ),
] );
}
if ( ! before && after ) {
onReplace( createBlock( 'core/paragraph', { content: before } ) );
}
} :
undefined
}
Expand Down
5 changes: 0 additions & 5 deletions packages/editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,6 @@ export class RichText extends Component {
} else if ( event.shiftKey || ! this.onSplit ) {
this.onChange( insertLineBreak( record ) );
} else {
// Some implementations of onSplit might also call onReplace, and
// calling onReplace() will destroy the editor, so it's
// important that we stop other handlers (e.g. ones
// registered by TinyMCE) from also handling this event.
event.stopImmediatePropagation();
this.splitContent();
}
}
Expand Down

0 comments on commit be995ca

Please sign in to comment.