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

Fix copy paste and delete error core paragraph with locking #14712

Merged
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-library/src/paragraph/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ class ParagraphBlock extends Component {
} }
unstableOnSplit={ this.splitBlock }
onMerge={ mergeBlocks }
onReplace={ this.onReplace }
onRemove={ () => onReplace( [] ) }
onReplace={ this.props.onReplace && this.onReplace }
onRemove={ onReplace && ( () => onReplace( [] ) ) }
aria-label={ content ? __( 'Paragraph block' ) : __( 'Empty block; start writing or type forward slash to choose a block' ) }
placeholder={ placeholder || __( 'Start writing or type / to choose a block' ) }
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

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>
<!-- /wp:image -->

<!-- wp:paragraph {\\"placeholder\\":\\"Add a description\\"} -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p></p></blockquote>
<!-- /wp:quote -->"
`;

exports[`cpt locking template_lock false should allow blocks to be inserted 1`] = `
"<!-- wp:image -->
<figure class=\\"wp-block-image\\"><img alt=\\"\\"/></figure>
Expand Down
9 changes: 9 additions & 0 deletions packages/e2e-tests/specs/plugins/cpt-locking.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
deactivatePlugin,
getEditedPostContent,
insertBlock,
pressKeyTimes,
} from '@wordpress/e2e-test-utils';

describe( 'cpt locking', () => {
Expand Down Expand Up @@ -58,6 +59,14 @@ describe( 'cpt locking', () => {
await page.$( 'button[aria-label="Move up"]' )
).toBeNull();
} );

it( 'should not error when deleting the cotents of a paragraph', async () => {
await page.click( '.block-editor-block-list__block[data-type="core/paragraph"] p' );
const textToType = 'Paragraph';
await page.keyboard.type( 'Paragraph' );
await pressKeyTimes( 'Backspace', textToType.length + 1 );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );

describe( 'template_lock insert', () => {
Expand Down