Skip to content

Commit

Permalink
Ensure cite is string when merging quote (#10678)
Browse files Browse the repository at this point in the history
* Ensure cite is string when merging quote

* Ensure createBlock returns string for html source

* Don't merge empty paragraphs
  • Loading branch information
ellatrix authored and tofumatt committed Oct 17, 2018
1 parent 0a59f18 commit a8b6e73
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/block-library/src/quote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,18 @@ export const settings = {
);
},

merge( attributes, attributesToMerge ) {
merge( attributes, { value, citation } ) {
if ( ! value || value === '<p></p>' ) {
return {
...attributes,
citation: attributes.citation + citation,
};
}

return {
...attributes,
value: attributes.value + attributesToMerge.value,
citation: attributes.citation + attributesToMerge.citation,
value: attributes.value + value,
citation: attributes.citation + citation,
};
},

Expand Down
4 changes: 4 additions & 0 deletions packages/blocks/src/api/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export function createBlock( name, blockAttributes = {}, innerBlocks = [] ) {
result[ key ] = schema.default;
}

if ( schema.source === 'html' && typeof result[ key ] !== 'string' ) {
result[ key ] = '';
}

if ( [ 'node', 'children' ].indexOf( schema.source ) !== -1 ) {
// Ensure value passed is always an array, which we're expecting in
// the RichText component to handle the deprecated value.
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/specs/blocks/__snapshots__/quote.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ exports[`Quote can be created by using > at the start of a paragraph block 1`] =
<blockquote class=\\"wp-block-quote\\"><p>A quote</p><p>Another paragraph</p></blockquote>
<!-- /wp:quote -->"
`;
exports[`Quote can be merged into from a paragraph 1`] = `
"<!-- wp:quote -->
<blockquote class=\\"wp-block-quote\\"><p>test</p></blockquote>
<!-- /wp:quote -->"
`;
9 changes: 9 additions & 0 deletions test/e2e/specs/blocks/quote.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,13 @@ describe( 'Quote', () => {
await convertBlock( 'Heading' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'can be merged into from a paragraph', async () => {
await insertBlock( 'Quote' );
await insertBlock( 'Paragraph' );
await page.keyboard.type( 'test' );
await pressTimes( 'ArrowLeft', 'test'.length );
await page.keyboard.press( 'Backspace' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );

0 comments on commit a8b6e73

Please sign in to comment.