Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing Flow: allow split out of caption on Enter #22290

Merged
merged 2 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -671,6 +673,11 @@ export class ImageEdit extends Component {
}
isSelected={ this.state.captionFocused }
inlineToolbar
__unstableOnSplitAtEnd={ () =>
insertBlocksAfter(
createBlock( 'core/paragraph' )
)
}
/>
) }

Expand Down