瀏覽代碼

Fixed: `view.UIElement` should be properly handled in list remove converter.

Szymon Cofalik 8 年之前
父節點
當前提交
0f9aadc039
共有 2 個文件被更改,包括 43 次插入2 次删除
  1. 4 2
      packages/ckeditor5-list/src/converters.js
  2. 39 0
      packages/ckeditor5-list/tests/listengine.js

+ 4 - 2
packages/ckeditor5-list/src/converters.js

@@ -102,8 +102,10 @@ export function modelViewRemove( evt, data, consumable, conversionApi ) {
 		return;
 	}
 
-	const viewPosition = conversionApi.mapper.toViewPosition( data.sourcePosition );
-	const viewItem = viewPosition.nodeAfter.is( 'li' ) ? viewPosition.nodeAfter : viewPosition.nodeAfter.getChild( 0 );
+	let viewPosition = conversionApi.mapper.toViewPosition( data.sourcePosition );
+	viewPosition = viewPosition.getLastMatchingPosition( value => !value.item.is( 'li' ) );
+
+	const viewItem = viewPosition.nodeAfter;
 
 	// 1. Break the container after and before the list item.
 	// This will create a view list with one view list item -- the one that changed type.

+ 39 - 0
packages/ckeditor5-list/tests/listengine.js

@@ -3345,6 +3345,45 @@ describe( 'ListEngine', () => {
 			expect( getViewData( editor.editing.view, { withoutSelection: true } ) )
 				.to.equal( '<ul><li>Foo<span></span><ul><li>Xxx</li><li>Yyy</li></ul></li></ul>' );
 		} );
+
+		describe( 'remove converter should properly handle ui elements', () => {
+			let uiElement;
+
+			beforeEach( () => {
+				editor.setData( '<ul><li>Foo</li><li>Bar</li></ul>' );
+				uiElement = new ViewUIElement( 'span' );
+			} );
+
+			it( 'ui element before <ul>', () => {
+				// Append ui element before <ul>.
+				viewRoot.insertChildren( 0, [ uiElement ] );
+
+				modelDoc.batch().remove( modelRoot.getChild( 0 ) );
+
+				expect( getViewData( editor.editing.view, { withoutSelection: true } ) )
+					.to.equal( '<span></span><ul><li>Bar</li></ul>' );
+			} );
+
+			it( 'ui element before first <li>', () => {
+				// Append ui element before <ul>.
+				viewRoot.getChild( 0 ).insertChildren( 0, [ uiElement ] );
+
+				modelDoc.batch().remove( modelRoot.getChild( 0 ) );
+
+				expect( getViewData( editor.editing.view, { withoutSelection: true } ) )
+					.to.equal( '<ul><span></span><li>Bar</li></ul>' );
+			} );
+
+			it( 'ui element in the middle of list', () => {
+				// Append ui element before <ul>.
+				viewRoot.getChild( 0 ).insertChildren( 1, [ uiElement ] );
+
+				modelDoc.batch().remove( modelRoot.getChild( 1 ) );
+
+				expect( getViewData( editor.editing.view, { withoutSelection: true } ) )
+					.to.equal( '<ul><li>Foo</li><span></span></ul>' );
+			} );
+		} );
 	} );
 
 	function getViewPosition( root, path ) {