Skip to content

Commit

Permalink
List v2: fix selection when creating paragraph from empty list item (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored and michalczaplinski committed Oct 18, 2022
1 parent a5efd9d commit 1736a08
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function useInnerBlockTemplateSync(
templateLock,
templateInsertUpdatesSelection
) {
const { getSelectedBlocksInitialCaretPosition } =
const { getSelectedBlocksInitialCaretPosition, isBlockSelected } =
useSelect( blockEditorStore );
const { replaceInnerBlocks } = useDispatch( blockEditorStore );
const innerBlocks = useSelect(
Expand Down Expand Up @@ -86,7 +86,8 @@ export default function useInnerBlockTemplateSync(
nextBlocks,
currentInnerBlocks.length === 0 &&
templateInsertUpdatesSelection &&
nextBlocks.length !== 0,
nextBlocks.length !== 0 &&
isBlockSelected( clientId ),
// This ensures the "initialPosition" doesn't change when applying the template
// If we're supposed to focus the block, we'll focus the first inner block
// otherwise, we won't apply any auto-focus.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- wp:list -->
<ul><!-- wp:list-item -->
<li></li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>1</p>
<!-- /wp:paragraph -->
9 changes: 9 additions & 0 deletions test/e2e/specs/editor/blocks/list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1225,4 +1225,13 @@ test.describe( 'List', () => {
<!-- /wp:list-item --></ul>
<!-- /wp:list -->` );
} );

test( 'can be exited to selected paragraph', async ( { editor, page } ) => {
await page.click( 'role=button[name="Add default block"i]' );
await page.keyboard.type( '* ' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '1' );

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

0 comments on commit 1736a08

Please sign in to comment.