Skip to content

Commit

Permalink
Fix (list): The list conversion will not throw an error if the list e…
Browse files Browse the repository at this point in the history
…lement is being surrounded with raw text nodes. Closes #8262.

Non-tagged elements will not blow up the list style feature
  • Loading branch information
mlewand authored Oct 20, 2020
2 parents 04207f9 + e45a515 commit e8b6f51
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ckeditor5-list/src/liststyleediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ function upcastListItemStyle() {
dispatcher.on( 'element:li', ( evt, data, conversionApi ) => {
const listParent = data.viewItem.parent;
const listStyle = listParent.getStyle( 'list-style-type' ) || DEFAULT_LIST_TYPE;
const listItem = data.modelRange.start.nodeAfter;
const listItem = data.modelRange.start.nodeAfter || data.modelRange.end.nodeBefore;

conversionApi.writer.setAttribute( 'listStyle', listStyle, listItem );
}, { priority: 'low' } );
Expand Down
37 changes: 37 additions & 0 deletions packages/ckeditor5-list/tests/liststyleediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,43 @@ describe( 'ListStyleEditing', () => {
'<paragraph>Paragraph.</paragraph>'
);
} );

// See: #8262.
describe( 'list conversion with surrounding text nodes', () => {
let editor;

beforeEach( () => {
return VirtualTestEditor
.create( {
plugins: [ ListStyleEditing ]
} )
.then( newEditor => {
editor = newEditor;
} );
} );

afterEach( () => {
return editor.destroy();
} );

it( 'should convert a list if raw text is before the list', () => {
editor.setData( 'Foo<ul><li>Foo</li></ul>' );

expect( editor.getData() ).to.equal( '<p>Foo</p><ul><li>Foo</li></ul>' );
} );

it( 'should convert a list if raw text is after the list', () => {
editor.setData( '<ul><li>Foo</li></ul>Foo' );

expect( editor.getData() ).to.equal( '<ul><li>Foo</li></ul><p>Foo</p>' );
} );

it( 'should convert a list if it is surrender by two text nodes', () => {
editor.setData( 'Foo<ul><li>Foo</li></ul>Foo' );

expect( editor.getData() ).to.equal( '<p>Foo</p><ul><li>Foo</li></ul><p>Foo</p>' );
} );
} );
} );
} );

Expand Down

0 comments on commit e8b6f51

Please sign in to comment.