From 378b862a036ce767bd690f859111d66b54336fde Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Tue, 13 Nov 2018 14:37:09 +0100 Subject: [PATCH] Reused a part of the repated code from ContainerElement. --- package.json | 2 +- src/utils.js | 17 +++++------------ tests/utils.js | 9 +++++++++ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index c582b18..e46c61a 100644 --- a/package.json +++ b/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", diff --git a/src/utils.js b/src/utils.js index 12311c9..af99e24 100644 --- a/src/utils.js +++ b/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 `
` 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 ); } diff --git a/tests/utils.js b/tests/utils.js index 8cea16b..32e0fd6 100644 --- a/tests/utils.js +++ b/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
element', () => { const item = createViewListItemElement( writer );