Skip to content

Commit

Permalink
Rich text: fix soft line break in caption on enter (#23622)
Browse files Browse the repository at this point in the history
* Rich text: fix soft line break in caption on enter

* Add e2e test
  • Loading branch information
ellatrix authored Jul 2, 2020
1 parent 49003cb commit 5a228b9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,18 +365,20 @@ function RichTextWrapper(
} else {
onChange( insertLineSeparator( value ) );
}
} else if ( shiftKey || ( ! canSplit && ! onSplitAtEnd ) ) {
if ( ! disableLineBreaks ) {
onChange( insert( value, '\n' ) );
}
} else if ( onSplitAtEnd && ! canSplit ) {
} else {
const { text, start, end } = value;
const canSplitAtEnd =
onSplitAtEnd && start === end && end === text.length;

if ( start === end && end === text.length ) {
if ( shiftKey || ( ! canSplit && ! canSplitAtEnd ) ) {
if ( ! disableLineBreaks ) {
onChange( insert( value, '\n' ) );
}
} else if ( ! canSplit && canSplitAtEnd ) {
onSplitAtEnd();
} else if ( canSplit ) {
splitValue( value );
}
} else if ( canSplit ) {
splitValue( value );
}
},
[
Expand Down
12 changes: 12 additions & 0 deletions packages/e2e-tests/specs/editor/blocks/image.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,16 @@ describe( 'Image', () => {
await page.evaluate( () => document.activeElement.innerHTML )
).toBe( '12' );
} );

it( 'should allow soft line breaks in caption', async () => {
await insertBlock( 'Image' );
await upload( '.wp-block-image input[type="file"]' );
await page.keyboard.type( '12' );
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.press( 'Enter' );

expect(
await page.evaluate( () => document.activeElement.innerHTML )
).toBe( '1<br data-rich-text-line-break="true">2' );
} );
} );

0 comments on commit 5a228b9

Please sign in to comment.