Skip to content

Commit 447dd27

Browse files
Fix copy paste and delete error core paragraph with locking (#14712)
* Fix: Copy / Paste error core/paragraph with locking * Add test case. * Update packages/block-library/src/paragraph/edit.js Co-Authored-By: jorgefilipecosta <[email protected]>
1 parent 0b2eb1c commit 447dd27

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

packages/block-library/src/paragraph/edit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ class ParagraphBlock extends Component {
244244
} }
245245
unstableOnSplit={ this.splitBlock }
246246
onMerge={ mergeBlocks }
247-
onReplace={ this.onReplace }
248-
onRemove={ () => onReplace( [] ) }
247+
onReplace={ this.props.onReplace && this.onReplace }
248+
onRemove={ onReplace && ( () => onReplace( [] ) ) }
249249
aria-label={ content ? __( 'Paragraph block' ) : __( 'Empty block; start writing or type forward slash to choose a block' ) }
250250
placeholder={ placeholder || __( 'Start writing or type / to choose a block' ) }
251251
/>

packages/e2e-tests/specs/plugins/__snapshots__/cpt-locking.test.js.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`cpt locking template_lock all should not error when deleting the cotents of a paragraph 1`] = `
4+
"<!-- wp:image -->
5+
<figure class=\\"wp-block-image\\"><img alt=\\"\\"/></figure>
6+
<!-- /wp:image -->
7+
8+
<!-- wp:paragraph {\\"placeholder\\":\\"Add a description\\"} -->
9+
<p></p>
10+
<!-- /wp:paragraph -->
11+
12+
<!-- wp:quote -->
13+
<blockquote class=\\"wp-block-quote\\"><p></p></blockquote>
14+
<!-- /wp:quote -->"
15+
`;
16+
317
exports[`cpt locking template_lock false should allow blocks to be inserted 1`] = `
418
"<!-- wp:image -->
519
<figure class=\\"wp-block-image\\"><img alt=\\"\\"/></figure>

packages/e2e-tests/specs/plugins/cpt-locking.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
deactivatePlugin,
99
getEditedPostContent,
1010
insertBlock,
11+
pressKeyTimes,
1112
} from '@wordpress/e2e-test-utils';
1213

1314
describe( 'cpt locking', () => {
@@ -58,6 +59,14 @@ describe( 'cpt locking', () => {
5859
await page.$( 'button[aria-label="Move up"]' )
5960
).toBeNull();
6061
} );
62+
63+
it( 'should not error when deleting the cotents of a paragraph', async () => {
64+
await page.click( '.block-editor-block-list__block[data-type="core/paragraph"] p' );
65+
const textToType = 'Paragraph';
66+
await page.keyboard.type( 'Paragraph' );
67+
await pressKeyTimes( 'Backspace', textToType.length + 1 );
68+
expect( await getEditedPostContent() ).toMatchSnapshot();
69+
} );
6170
} );
6271

6372
describe( 'template_lock insert', () => {

0 commit comments

Comments
 (0)