Skip to content

Commit

Permalink
fix #22550 and allow enter to insert line breaks even if template is …
Browse files Browse the repository at this point in the history
…locked (#23330)

* fix #22550 and allow enter to insert line breaks in richtext

* add e2e test

* Restore isSelected condition

Co-authored-by: Ella van Durpe <[email protected]>
  • Loading branch information
2 people authored and youknowriad committed Jul 27, 2020
1 parent 9cda154 commit 6e29088
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const BlockComponent = forwardRef(
enableAnimation,
index,
className,
isLocked,
name,
mode,
blockTitle,
Expand Down Expand Up @@ -258,8 +257,8 @@ const BlockComponent = forwardRef(
data-block={ clientId }
data-type={ name }
data-title={ blockTitle }
// Only allow shortcuts when a blocks is selected and not locked.
onKeyDown={ isSelected && ! isLocked ? onKeyDown : undefined }
// Only allow shortcuts when a blocks is selected.
onKeyDown={ isSelected ? onKeyDown : undefined }
// Only allow selection to be started from a selected block.
onMouseLeave={ isSelected ? onMouseLeave : undefined }
// No need to have these listeners for hover class in edit mode.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`cpt locking template_lock all should insert line breaks when using enter and shift-enter 1`] = `
"<!-- wp:image -->
<figure class=\\"wp-block-image\\"><img alt=\\"\\"/></figure>
<!-- /wp:image -->
<!-- wp:paragraph {\\"placeholder\\":\\"Add a description\\"} -->
<p>First line<br>Second line<br>Third line</p>
<!-- /wp:paragraph -->
<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p></p></blockquote>
<!-- /wp:quote -->
<!-- wp:columns -->
<div class=\\"wp-block-columns\\"></div>
<!-- /wp:columns -->"
`;
exports[`cpt locking template_lock all should not error when deleting the cotents of a paragraph 1`] = `
"<!-- wp:image -->
<figure class=\\"wp-block-image\\"><img alt=\\"\\"/></figure>
Expand Down
13 changes: 13 additions & 0 deletions packages/e2e-tests/specs/editor/plugins/cpt-locking.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getEditedPostContent,
insertBlock,
pressKeyTimes,
pressKeyWithModifier,
setPostContent,
} from '@wordpress/e2e-test-utils';

Expand Down Expand Up @@ -85,6 +86,18 @@ describe( 'cpt locking', () => {
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should insert line breaks when using enter and shift-enter', async () => {
await page.click(
'.block-editor-block-list__block[data-type="core/paragraph"]'
);
await page.keyboard.type( 'First line' );
await pressKeyTimes( 'Enter', 1 );
await page.keyboard.type( 'Second line' );
await pressKeyWithModifier( 'shift', 'Enter' );
await page.keyboard.type( 'Third line' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should show invalid template notice if the blocks do not match the templte', async () => {
const content = await getEditedPostContent();
const [ , contentWithoutImage ] = content.split(
Expand Down

0 comments on commit 6e29088

Please sign in to comment.