Skip to content

Commit

Permalink
List Block: Do not split on line breaks when multiple blocks are tran…
Browse files Browse the repository at this point in the history
…sformed (#13832)
  • Loading branch information
ellatrix authored and youknowriad committed Mar 6, 2019
1 parent 3788066 commit 29603e9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/block-library/src/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,17 @@ export const settings = {
transform: ( blockAttributes ) => {
return createBlock( 'core/list', {
values: toHTMLString( {
value: join( blockAttributes.map( ( { content } ) =>
replace( create( { html: content } ), /\n/g, LINE_SEPARATOR )
), LINE_SEPARATOR ),
value: join( blockAttributes.map( ( { content } ) => {
const value = create( { html: content } );

if ( blockAttributes.length > 1 ) {
return value;
}

// When converting only one block, transform
// every line to a list item.
return replace( value, /\n/g, LINE_SEPARATOR );
} ), LINE_SEPARATOR ),
multilineTag: 'li',
} ),
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ exports[`List should insert a line break on shift+enter in a non trailing list i
<!-- /wp:list -->"
`;
exports[`List should not transform lines in block when transforming multiple blocks 1`] = `
"<!-- wp:list -->
<ul><li>one<br>...</li><li>two</li></ul>
<!-- /wp:list -->"
`;
exports[`List should outdent with children 1`] = `
"<!-- wp:list -->
<ul><li>a<ul><li>b<ul><li>c</li></ul></li></ul></li></ul>
Expand Down
15 changes: 15 additions & 0 deletions packages/e2e-tests/specs/blocks/list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ describe( 'List', () => {
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should not transform lines in block when transforming multiple blocks', async () => {
await clickBlockAppender();
await page.keyboard.type( 'one' );
await pressKeyWithModifier( 'shift', 'Enter' );
await page.keyboard.type( '...' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'two' );
await page.keyboard.down( 'Shift' );
await page.click( '[data-type="core/paragraph"]' );
await page.keyboard.up( 'Shift' );
await transformBlockTo( 'List' );

expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'can be converted to paragraphs', async () => {
await insertBlock( 'List' );
await page.keyboard.type( 'one' );
Expand Down

0 comments on commit 29603e9

Please sign in to comment.