Skip to content

Commit

Permalink
Writing Flow: allow split out of caption on Enter (#22290)
Browse files Browse the repository at this point in the history
* Image: allow split out of caption on Enter

* Mark unstable
  • Loading branch information
ellatrix authored May 19, 2020
1 parent 4bb758d commit 7fa12a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ function RichTextWrapper(
onRemove,
onMerge,
onSplit,
__unstableOnSplitAtEnd: onSplitAtEnd,
__unstableOnSplitMiddle: onSplitMiddle,
identifier,
// To do: find a better way to implicitly inherit props.
Expand Down Expand Up @@ -360,11 +361,17 @@ function RichTextWrapper(
} else {
onChange( insertLineSeparator( value ) );
}
} else if ( shiftKey || ! canSplit ) {
} else if ( shiftKey || ( ! canSplit && ! onSplitAtEnd ) ) {
if ( ! disableLineBreaks ) {
onChange( insert( value, '\n' ) );
}
} else {
} else if ( onSplitAtEnd && ! canSplit ) {
const { text, start, end } = value;

if ( start === end && end === text.length ) {
onSplitAtEnd();
}
} else if ( canSplit ) {
splitValue( value );
}
},
Expand Down
7 changes: 7 additions & 0 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { __, sprintf } from '@wordpress/i18n';
import { getPath } from '@wordpress/url';
import { withViewportMatch } from '@wordpress/viewport';
import { image as icon } from '@wordpress/icons';
import { createBlock } from '@wordpress/blocks';

/**
* Internal dependencies
Expand Down Expand Up @@ -334,6 +335,7 @@ export class ImageEdit extends Component {
isRTL,
onResizeStart,
onResizeStop,
insertBlocksAfter,
} = this.props;
const {
url,
Expand Down Expand Up @@ -672,6 +674,11 @@ export class ImageEdit extends Component {
}
isSelected={ this.state.captionFocused }
inlineToolbar
__unstableOnSplitAtEnd={ () =>
insertBlocksAfter(
createBlock( 'core/paragraph' )
)
}
/>
) }

Expand Down

0 comments on commit 7fa12a3

Please sign in to comment.