Skip to content

Commit

Permalink
Fix block merging regression (#23901)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Jul 13, 2020
1 parent 2eaee1c commit b4b9b2a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
14 changes: 11 additions & 3 deletions packages/block-editor/src/components/block-list/block-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
forwardRef,
} from '@wordpress/element';
import { focus, isTextField, placeCaretAtHorizontalEdge } from '@wordpress/dom';
import { ENTER } from '@wordpress/keycodes';
import { ENTER, BACKSPACE, DELETE } from '@wordpress/keycodes';
import { __, sprintf } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';

Expand Down Expand Up @@ -75,7 +75,9 @@ const BlockComponent = forwardRef(
},
[ isSelected ]
);
const { insertDefaultBlock } = useDispatch( 'core/block-editor' );
const { insertDefaultBlock, removeBlock } = useDispatch(
'core/block-editor'
);
const fallbackRef = useRef();
const isAligned = wrapperProps && !! wrapperProps[ 'data-align' ];
wrapper = wrapper || fallbackRef;
Expand Down Expand Up @@ -169,7 +171,11 @@ const BlockComponent = forwardRef(
props.onKeyDown( event );
}

if ( keyCode !== ENTER ) {
if (
keyCode !== ENTER &&
keyCode !== BACKSPACE &&
keyCode !== DELETE
) {
return;
}

Expand All @@ -181,6 +187,8 @@ const BlockComponent = forwardRef(

if ( keyCode === ENTER ) {
insertDefaultBlock( {}, rootClientId, index + 1 );
} else {
removeBlock( clientId );
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function KeyboardShortcuts() {
},
[ clientIds, removeBlocks ]
),
{ isDisabled: clientIds.length < 1 }
{ isDisabled: clientIds.length < 2 }
);

useShortcut(
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-tests/specs/editor/blocks/image.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe( 'Image', () => {
);
expect( await getEditedPostContent() ).toMatch( regex3 );

await page.click( '.wp-block-image img' );
await page.keyboard.press( 'Backspace' );

expect( await getEditedPostContent() ).toBe( '' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ exports[`Writing Flow should merge forwards 1`] = `
<!-- /wp:paragraph -->"
`;
exports[`Writing Flow should merge paragraphs 1`] = `
"<!-- wp:paragraph -->
<p>12</p>
<!-- /wp:paragraph -->"
`;
exports[`Writing Flow should navigate around inline boundaries 1`] = `
"<!-- wp:paragraph -->
<p>FirstAfter</p>
Expand Down
11 changes: 11 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 @@ -410,6 +410,17 @@ describe( 'Writing Flow', () => {
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should merge paragraphs', 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( 'ArrowLeft' );
await page.keyboard.press( 'Backspace' );

expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should merge forwards', async () => {
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '1' );
Expand Down

0 comments on commit b4b9b2a

Please sign in to comment.