From 9b9931f64394c1c3f1d6c1d224fabb226a95a427 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 21 Sep 2023 12:08:01 +0400 Subject: [PATCH] Block Editor: Fix 'isBlockSubtreeDisabled' private selector (#54618) * Fix selector dependencies * Improve child subtree check * Add e2e tests --- .../src/store/private-selectors.js | 10 +++-- .../editor/various/content-only-lock.spec.js | 45 +++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/store/private-selectors.js b/packages/block-editor/src/store/private-selectors.js index e77e478ba60466..698da537728e01 100644 --- a/packages/block-editor/src/store/private-selectors.js +++ b/packages/block-editor/src/store/private-selectors.js @@ -45,9 +45,8 @@ export function getLastInsertedBlocksClientIds( state ) { export const isBlockSubtreeDisabled = createSelector( ( state, clientId ) => { const isChildSubtreeDisabled = ( childClientId ) => { - const mode = state.blockEditingModes.get( childClientId ); return ( - ( mode === undefined || mode === 'disabled' ) && + getBlockEditingMode( state, childClientId ) === 'disabled' && getBlockOrder( state, childClientId ).every( isChildSubtreeDisabled ) @@ -58,7 +57,12 @@ export const isBlockSubtreeDisabled = createSelector( getBlockOrder( state, clientId ).every( isChildSubtreeDisabled ) ); }, - ( state ) => [ state.blockEditingModes, state.blocks.parents ] + ( state ) => [ + state.blocks.parents, + state.blocks.order, + state.blockEditingModes, + state.blockListSettings, + ] ); /** diff --git a/test/e2e/specs/editor/various/content-only-lock.spec.js b/test/e2e/specs/editor/various/content-only-lock.spec.js index d6ea152d65f3ff..8e07741db29b19 100644 --- a/test/e2e/specs/editor/various/content-only-lock.spec.js +++ b/test/e2e/specs/editor/various/content-only-lock.spec.js @@ -29,4 +29,49 @@ test.describe( 'Content-only lock', () => { await page.keyboard.type( ' World' ); expect( await editor.getEditedPostContent() ).toMatchSnapshot(); } ); + + // See: https://github.com/WordPress/gutenberg/pull/54618 + test( 'should be able to edit the content of deeply nested blocks', async ( { + editor, + page, + pageUtils, + } ) => { + // Add content only locked block in the code editor + await pageUtils.pressKeys( 'secondary+M' ); // Emulates CTRL+Shift+Alt + M => toggle code editor + + await page.getByPlaceholder( 'Start writing with text or HTML' ) + .fill( ` +
+
+

Hello

+
+
+` ); + + await pageUtils.pressKeys( 'secondary+M' ); + await page.waitForSelector( 'iframe[name="editor-canvas"]' ); + await editor.canvas.click( 'role=document[name="Paragraph block"i]' ); + await page.keyboard.type( ' WP' ); + await expect.poll( editor.getBlocks ).toMatchObject( [ + { + name: 'core/group', + attributes: { + layout: { type: 'constrained' }, + templateLock: 'contentOnly', + }, + innerBlocks: [ + { + name: 'core/group', + attributes: { layout: { type: 'constrained' } }, + innerBlocks: [ + { + name: 'core/paragraph', + attributes: { content: 'Hello WP' }, + }, + ], + }, + ], + }, + ] ); + } ); } );