From a478046f0200d5457c16d35b1935a7c1e79d91b8 Mon Sep 17 00:00:00 2001 From: Jorge Date: Fri, 29 Mar 2019 16:52:20 +0000 Subject: [PATCH 1/3] Fix: Copy / Paste error core/paragraph with locking --- packages/block-library/src/paragraph/edit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/paragraph/edit.js b/packages/block-library/src/paragraph/edit.js index 0ed9c5c91b582..1f117d7f4cd9d 100644 --- a/packages/block-library/src/paragraph/edit.js +++ b/packages/block-library/src/paragraph/edit.js @@ -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={ this.props.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' ) } /> From bdd1e0bfcfc78ffad367a3cdccb2f2be24291d64 Mon Sep 17 00:00:00 2001 From: Jorge Date: Fri, 29 Mar 2019 18:07:07 +0000 Subject: [PATCH 2/3] Add test case. --- .../plugins/__snapshots__/cpt-locking.test.js.snap | 14 ++++++++++++++ .../e2e-tests/specs/plugins/cpt-locking.test.js | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/packages/e2e-tests/specs/plugins/__snapshots__/cpt-locking.test.js.snap b/packages/e2e-tests/specs/plugins/__snapshots__/cpt-locking.test.js.snap index de467ce40d3e8..24166c89f310b 100644 --- a/packages/e2e-tests/specs/plugins/__snapshots__/cpt-locking.test.js.snap +++ b/packages/e2e-tests/specs/plugins/__snapshots__/cpt-locking.test.js.snap @@ -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`] = ` +" +
\\"\\"/
+ + + +

+ + + +

+" +`; + exports[`cpt locking template_lock false should allow blocks to be inserted 1`] = ` "
\\"\\"/
diff --git a/packages/e2e-tests/specs/plugins/cpt-locking.test.js b/packages/e2e-tests/specs/plugins/cpt-locking.test.js index 2a858b8a5c849..4239716c6c1a4 100644 --- a/packages/e2e-tests/specs/plugins/cpt-locking.test.js +++ b/packages/e2e-tests/specs/plugins/cpt-locking.test.js @@ -8,6 +8,7 @@ import { deactivatePlugin, getEditedPostContent, insertBlock, + pressKeyTimes, } from '@wordpress/e2e-test-utils'; describe( 'cpt locking', () => { @@ -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', () => { From 6ea624e677b11b8658996b0a3480d4793be10da2 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Tue, 30 Apr 2019 10:25:38 +0100 Subject: [PATCH 3/3] Update packages/block-library/src/paragraph/edit.js Co-Authored-By: jorgefilipecosta --- packages/block-library/src/paragraph/edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/paragraph/edit.js b/packages/block-library/src/paragraph/edit.js index 1f117d7f4cd9d..91dc83c69984f 100644 --- a/packages/block-library/src/paragraph/edit.js +++ b/packages/block-library/src/paragraph/edit.js @@ -245,7 +245,7 @@ class ParagraphBlock extends Component { unstableOnSplit={ this.splitBlock } onMerge={ mergeBlocks } onReplace={ this.props.onReplace && this.onReplace } - onRemove={ this.props.onReplace && ( () => 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' ) } />