From 5e4034b02dd5dbcbbdc8a2fe449e723ddc5584bd Mon Sep 17 00:00:00 2001 From: iseulde Date: Wed, 27 Feb 2019 16:42:45 +0100 Subject: [PATCH] RichText: introduce onEnterAtEnd --- packages/block-library/src/image/edit.js | 3 +++ .../editor/src/components/rich-text/index.js | 16 +++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index deaeaf79766dc..d06f3fd51eaed 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -46,6 +46,7 @@ import { Component, Fragment } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; import { getPath } from '@wordpress/url'; import { withViewportMatch } from '@wordpress/viewport'; +import { createBlock } from '@wordpress/blocks'; /** * Internal dependencies @@ -356,6 +357,7 @@ class ImageEdit extends Component { noticeUI, toggleSelection, isRTL, + insertBlocksAfter, } = this.props; const { url, @@ -693,6 +695,7 @@ class ImageEdit extends Component { onChange={ ( value ) => setAttributes( { caption: value } ) } isSelected={ this.state.captionFocused } inlineToolbar + onEnterAtEnd={ () => insertBlocksAfter( createBlock( 'core/paragraph' ) ) } /> ) } diff --git a/packages/editor/src/components/rich-text/index.js b/packages/editor/src/components/rich-text/index.js index ccfe32326d944..1aa5584e2adda 100644 --- a/packages/editor/src/components/rich-text/index.js +++ b/packages/editor/src/components/rich-text/index.js @@ -645,15 +645,21 @@ export class RichText extends Component { } } - if ( this.multilineTag ) { - if ( event.shiftKey ) { - this.onChange( insertLineBreak( record ) ); - } else if ( this.onSplit && isEmptyLine( record ) ) { + if ( event.shiftKey ) { + this.onChange( insertLineBreak( record ) ); + } else if ( this.multilineTag ) { + if ( this.onSplit && isEmptyLine( record ) ) { this.onSplit( ...split( record ).map( this.valueToFormat ) ); } else { this.onChange( insertLineSeparator( record ) ); } - } else if ( event.shiftKey || ! this.onSplit ) { + } else if ( + this.props.onEnterAtEnd && + isCollapsed( record ) && + record.text.length === record.start + ) { + this.props.onEnterAtEnd(); + } else if ( ! this.onSplit ) { this.onChange( insertLineBreak( record ) ); } else { this.splitContent();