Skip to content

Commit

Permalink
Image: allow split out of caption on Enter
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed May 13, 2020
1 parent 47389d5 commit 60f58d5
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,
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 ) {
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 @@ -671,6 +673,11 @@ export class ImageEdit extends Component {
}
isSelected={ this.state.captionFocused }
inlineToolbar
onSplitAtEnd={ () =>
insertBlocksAfter(
createBlock( 'core/paragraph' )
)
}
/>
) }

Expand Down

0 comments on commit 60f58d5

Please sign in to comment.