Skip to content

Commit

Permalink
Fix content locked patterns (#46494)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Dec 13, 2022
1 parent 98409e9 commit 570e7d9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2690,8 +2690,8 @@ export const __unstableGetContentLockingParent = createSelector(
( state, clientId ) => {
let current = clientId;
let result;
while ( !! state.blocks.parents[ current ] ) {
current = state.blocks.parents[ current ];
while ( state.blocks.parents.has( current ) ) {
current = state.blocks.parents.get( current );
if ( getTemplateLock( state, current ) === 'contentOnly' ) {
result = current;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- wp:group {"templateLock":"contentOnly","layout":{"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:paragraph -->
<p>Hello World</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->
31 changes: 31 additions & 0 deletions test/e2e/specs/editor/various/content-only-lock.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Content-only lock', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
} );

test( 'should be able to edit the content of blocks with content-only lock', async ( {
editor,
page,
pageUtils,
} ) => {
// Add content only locked block in the code editor
await pageUtils.pressKeyWithModifier( 'secondary', 'M' ); // Emulates CTRL+Shift+Alt + M => toggle code editor
await page.click( '.editor-post-text-editor' );
await page.keyboard
.type( `<!-- wp:group {"templateLock":"contentOnly","layout":{"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:paragraph -->
<p>Hello</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->` );
await pageUtils.pressKeyWithModifier( 'secondary', 'M' );

await page.click( 'role=document[name="Paragraph block"i]' );
await page.keyboard.type( ' World' );
expect( await editor.getEditedPostContent() ).toMatchSnapshot();
} );
} );

0 comments on commit 570e7d9

Please sign in to comment.