Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge 378b862 into bfda8b2
Browse files Browse the repository at this point in the history
  • Loading branch information
pomek committed Nov 13, 2018
2 parents bfda8b2 + 378b862 commit 164ce05
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down
12 changes: 9 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*
Expand All @@ -15,16 +17,20 @@
*/
export function createViewListItemElement( writer ) {
const viewItem = writer.createContainerElement( 'li' );
viewItem.getFillerOffset = getFillerOffset;
viewItem.getFillerOffset = _getFillerOffset;

return viewItem;
}

// 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' );

return this.isEmpty || hasOnlyLists ? 0 : null;
if ( this.isEmpty || hasOnlyLists ) {
return 0;
}

return getFillerOffset.call( this );
}
62 changes: 62 additions & 0 deletions tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,68 @@ describe( 'utils', () => {

expect( item.getFillerOffset() ).to.be.null;
} );

// Block filler is required after the `<br>` element if the element is the last child in the container.
// See: https://github.com/ckeditor/ckeditor5/issues/1312#issuecomment-436669045.
describe( 'for <br> elements in container', () => {
it( 'returns offset of the last child which is the <br> element (1)', () => {
const item = createViewListItemElement( writer );

writer.insert( writer.createPositionAt( item, 0 ), writer.createEmptyElement( 'br' ) );

expect( item.getFillerOffset() ).to.equal( 1 );
} );

it( 'returns offset of the last child which is the <br> element (2)', () => {
const item = createViewListItemElement( writer );

writer.insert( writer.createPositionAt( item, 0 ), writer.createEmptyElement( 'br' ) );
writer.insert( writer.createPositionAt( item, 1 ), writer.createEmptyElement( 'br' ) );

expect( item.getFillerOffset() ).to.equal( 2 );
} );

it( 'always returns the last <br> element in the container', () => {
const item = createViewListItemElement( writer );

writer.insert( writer.createPositionAt( item, 0 ), writer.createText( 'foo' ) );
writer.insert( writer.createPositionAt( item, 1 ), writer.createEmptyElement( 'br' ) );
writer.insert( writer.createPositionAt( item, 2 ), writer.createEmptyElement( 'br' ) );

expect( item.getFillerOffset() ).to.equal( 3 );
} );

it( 'works fine with non-empty container with multi <br> elements', () => {
const item = createViewListItemElement( writer );

writer.insert( writer.createPositionAt( item, 0 ), writer.createText( 'foo' ) );
writer.insert( writer.createPositionAt( item, 1 ), writer.createEmptyElement( 'br' ) );
writer.insert( writer.createPositionAt( item, 2 ), writer.createText( 'bar' ) );
writer.insert( writer.createPositionAt( item, 3 ), writer.createEmptyElement( 'br' ) );

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 );

writer.insert(
writer.createPositionAt( item, 0 ),
writer.createEmptyElement( 'img' )
);

expect( item.getFillerOffset() ).to.be.null;
} );
} );
} );
} );
} );

0 comments on commit 164ce05

Please sign in to comment.