From e45a51585bd947b09241e78f417fad9918793c85 Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Tue, 20 Oct 2020 09:47:31 +0200 Subject: [PATCH] List conversion with surrounding text nodes. --- .../ckeditor5-list/src/liststyleediting.js | 2 +- .../ckeditor5-list/tests/liststyleediting.js | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/ckeditor5-list/src/liststyleediting.js b/packages/ckeditor5-list/src/liststyleediting.js index 22f13e87cac..1ccdd4909e7 100644 --- a/packages/ckeditor5-list/src/liststyleediting.js +++ b/packages/ckeditor5-list/src/liststyleediting.js @@ -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' } ); diff --git a/packages/ckeditor5-list/tests/liststyleediting.js b/packages/ckeditor5-list/tests/liststyleediting.js index f20e027e97c..06f6eed13af 100644 --- a/packages/ckeditor5-list/tests/liststyleediting.js +++ b/packages/ckeditor5-list/tests/liststyleediting.js @@ -333,6 +333,43 @@ describe( 'ListStyleEditing', () => { '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' ); + + expect( editor.getData() ).to.equal( '

Foo

' ); + } ); + + it( 'should convert a list if raw text is after the list', () => { + editor.setData( 'Foo' ); + + expect( editor.getData() ).to.equal( '

Foo

' ); + } ); + + it( 'should convert a list if it is surrender by two text nodes', () => { + editor.setData( 'FooFoo' ); + + expect( editor.getData() ).to.equal( '

Foo

Foo

' ); + } ); + } ); } ); } );