ソースを参照

Reused a part of the repated code from ContainerElement.

Kamil Piechaczek 7 年 前
コミット
afd568b82f

+ 1 - 1
packages/ckeditor5-list/package.json

@@ -11,6 +11,7 @@
   ],
   "dependencies": {
     "@ckeditor/ckeditor5-core": "^11.0.1",
+    "@ckeditor/ckeditor5-engine": "^11.0.0",
     "@ckeditor/ckeditor5-paragraph": "^10.0.3",
     "@ckeditor/ckeditor5-ui": "^11.1.0",
     "@ckeditor/ckeditor5-utils": "^11.0.0"
@@ -20,7 +21,6 @@
     "@ckeditor/ckeditor5-block-quote": "^10.1.0",
     "@ckeditor/ckeditor5-clipboard": "^10.0.3",
     "@ckeditor/ckeditor5-editor-classic": "^11.0.1",
-    "@ckeditor/ckeditor5-engine": "^11.0.0",
     "@ckeditor/ckeditor5-enter": "^10.1.2",
     "@ckeditor/ckeditor5-heading": "^10.1.0",
     "@ckeditor/ckeditor5-link": "^10.0.4",

+ 5 - 12
packages/ckeditor5-list/src/utils.js

@@ -7,6 +7,8 @@
  * @module list/utils
  */
 
+import { getFillerOffset } from '@ckeditor/ckeditor5-engine/src/view/containerelement';
+
 /**
  * Creates list item {@link module:engine/view/containerelement~ContainerElement}.
  *
@@ -15,7 +17,7 @@
  */
 export function createViewListItemElement( writer ) {
 	const viewItem = writer.createContainerElement( 'li' );
-	viewItem.getFillerOffset = getFillerOffset;
+	viewItem.getFillerOffset = _getFillerOffset;
 
 	return viewItem;
 }
@@ -23,21 +25,12 @@ export function createViewListItemElement( writer ) {
 // Implementation of getFillerOffset for view list item element.
 //
 // @returns {Number|null} Block filler offset or `null` if block filler is not needed.
-function getFillerOffset() {
+function _getFillerOffset() {
 	const hasOnlyLists = !this.isEmpty && ( this.getChild( 0 ).name == 'ul' || this.getChild( 0 ).name == 'ol' );
 
 	if ( this.isEmpty || hasOnlyLists ) {
 		return 0;
 	}
 
-	const children = [ ...this.getChildren() ];
-	const lastChild = children[ this.childCount - 1 ];
-
-	// Block filler is required after a `<br>` if it's the last element in its container.
-	// See: https://github.com/ckeditor/ckeditor5/issues/1312#issuecomment-436669045.
-	if ( lastChild && lastChild.is( 'element', 'br' ) ) {
-		return this.childCount;
-	}
-
-	return null;
+	return getFillerOffset.call( this );
 }

+ 9 - 0
packages/ckeditor5-list/tests/utils.js

@@ -111,6 +111,15 @@ describe( 'utils', () => {
 					expect( item.getFillerOffset() ).to.equal( 4 );
 				} );
 
+				it( 'ignores the ui elements', () => {
+					const item = createViewListItemElement( writer );
+
+					writer.insert( writer.createPositionAt( item, 0 ), writer.createUIElement( 'span' ) );
+					writer.insert( writer.createPositionAt( item, 1 ), writer.createEmptyElement( 'br' ) );
+
+					expect( item.getFillerOffset() ).to.equal( 2 );
+				} );
+
 				it( 'empty element must be the <br> element', () => {
 					const item = createViewListItemElement( writer );