浏览代码

Merge pull request #122 from ckeditor/t/121

Fix: Some specific content resulted in creating additional, incorrect list items when loaded. Closes #121.
Piotrek Koszuliński 6 年之前
父节点
当前提交
767b63c0ab
共有 2 个文件被更改,包括 25 次插入8 次删除
  1. 5 5
      packages/ckeditor5-list/src/converters.js
  2. 20 3
      packages/ckeditor5-list/tests/listediting.js

+ 5 - 5
packages/ckeditor5-list/src/converters.js

@@ -373,12 +373,12 @@ export function viewModelConverter( evt, data, conversionApi ) {
 		// Result range starts before the first item and ends after the last.
 		data.modelRange = writer.createRange( data.modelCursor, nextPosition );
 
-		// When modelCursor parent had to be split to insert list item.
+		// When `data.modelCursor` parent had to be split to insert list item...
 		if ( splitResult.cursorParent ) {
-			// Then continue conversion in split element.
+			// Continue conversion in the split element.
 			data.modelCursor = writer.createPositionAt( splitResult.cursorParent, 0 );
 		} else {
-			// Otherwise continue conversion after last list item.
+			// Otherwise continue conversion after the last list item.
 			data.modelCursor = data.modelRange.end;
 		}
 	}
@@ -826,7 +826,7 @@ function viewToModelListItemChildrenConverter( listItemModel, viewChildren, conv
 			const result = conversionApi.convertItem( child, writer.createPositionAt( lastListItem, 'end' ) );
 			const convertedChild = result.modelRange.start.nodeAfter;
 
-			nextPosition = result.modelCursor;
+			nextPosition = writer.createPositionAfter( result.modelCursor.parent );
 
 			// If there is a block element child being converted it may split the current list item, for example:
 			//
@@ -839,7 +839,7 @@ function viewToModelListItemChildrenConverter( listItemModel, viewChildren, conv
 			// so we need to update reference to `lastListItem`.
 			if ( convertedChild && convertedChild.is( 'element' ) &&
 				!conversionApi.schema.checkChild( lastListItem, convertedChild.name ) ) {
-				lastListItem = nextPosition.parent;
+				lastListItem = result.modelCursor.parent;
 
 				// Depending on the used converter for block elements, usually the position (`result.modelCursor`
 				// marked as # below) points to the second list item after conversion:

+ 20 - 3
packages/ckeditor5-list/tests/listediting.js

@@ -1514,7 +1514,7 @@ describe( 'ListEditing', () => {
 							'</ol>' +
 						'</li>' +
 						'<li>k</li>' +
-					'</ol>'
+					'</ul>'
 				);
 			} );
 
@@ -4017,7 +4017,7 @@ describe( 'ListEditing', () => {
 				allow: 'inline'
 			} );
 
-			editor.data.set( '<ul><li>foo</li></ul>', 'title' );
+			editor.data.set( { title: '<ul><li>foo</li></ul>' } );
 
 			expect( getModelData( model, { rootName: 'title', withoutSelection: true } ) ).to.equal( '' );
 		} );
@@ -4069,7 +4069,7 @@ describe( 'ListEditing', () => {
 			editor.setData(
 				'<div>' +
 					'<ul>' +
-					'<li>foo</li>' +
+						'<li>foo</li>' +
 					'</ul>' +
 					'def' +
 				'</div>'
@@ -4080,6 +4080,23 @@ describe( 'ListEditing', () => {
 				'<div>def</div>'
 			);
 		} );
+
+		// https://github.com/ckeditor/ckeditor5-list/issues/121
+		it( 'should correctly set data.modelCursor', () => {
+			editor.setData(
+				'<ul>' +
+					'<li>a</li>' +
+					'<li>b</li>' +
+				'</ul>' +
+				'c'
+			);
+
+			expect( getModelData( model, { withoutSelection: true } ) ).to.equal(
+				'<listItem listIndent="0" listType="bulleted">a</listItem>' +
+				'<listItem listIndent="0" listType="bulleted">b</listItem>' +
+				'<paragraph>c</paragraph>'
+			);
+		} );
 	} );
 
 	function getViewPosition( root, path, view ) {