Skip to content

Commit

Permalink
[RichText]: Fix wrong block merging when pressing delete consecutiv…
Browse files Browse the repository at this point in the history
…ely (#38991)

* [RichText]: Fix wrong block merging when pressing  `delete` consecutively

* add e2e test
  • Loading branch information
ntsekouras authored Feb 23, 2022
1 parent b837704 commit d8440c6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/e2e-tests/specs/editor/various/writing-flow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,33 @@ describe( 'Writing Flow', () => {
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should merge forwards properly on multiple triggers', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '1' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '2' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '3' );
await pressKeyTimes( 'ArrowUp', 2 );
await pressKeyTimes( 'Delete', 2 );
expect( await getEditedPostContent() ).toMatchInlineSnapshot( `
"<!-- wp:paragraph -->
<p>1</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>3</p>
<!-- /wp:paragraph -->"
` );
await page.keyboard.press( 'Delete' );

expect( await getEditedPostContent() ).toMatchInlineSnapshot( `
"<!-- wp:paragraph -->
<p>13</p>
<!-- /wp:paragraph -->"
` );
} );

it( 'should preserve horizontal position when navigating vertically between blocks', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'abc' );
Expand Down
1 change: 1 addition & 0 deletions packages/rich-text/src/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export function useRichText( {
useLayoutEffect( () => {
if ( didMount.current && value !== _value.current ) {
applyFromProps();
forceRender();
}
}, [ value ] );

Expand Down

0 comments on commit d8440c6

Please sign in to comment.