Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Editor: Fix content locked patterns #46494

Merged
merged 2 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
} );
} );