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

Commit ba3d641

Browse files
authored
Merge pull request #1426 from ckeditor/t/1422
Fix: Block filler will be inserted into the container if its last child is a `<br>` element. Closes #1422.
2 parents 62a0324 + a0c8bf0 commit ba3d641

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/view/containerelement.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@ export default class ContainerElement extends Element {
8080
//
8181
// @returns {Number|null} Block filler offset or `null` if block filler is not needed.
8282
function getFillerOffset() {
83-
for ( const child of this.getChildren() ) {
83+
const children = [ ...this.getChildren() ];
84+
const lastChild = children[ this.childCount - 1 ];
85+
86+
// Block filler is required after a `<br>` if it's the last element in its container. See #1422.
87+
if ( lastChild && lastChild.is( 'element', 'br' ) ) {
88+
return this.childCount;
89+
}
90+
91+
for ( const child of children ) {
8492
// If there's any non-UI element – don't render the bogus.
8593
if ( !child.is( 'uiElement' ) ) {
8694
return null;

tests/view/containerelement.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,40 @@ describe( 'ContainerElement', () => {
5959
it( 'should return null if element is not empty', () => {
6060
expect( parse( '<container:p>foo</container:p>' ).getFillerOffset() ).to.be.null;
6161
} );
62+
63+
// Block filler is required after the `<br>` element if the element is the last child in the container. See #1422.
64+
describe( 'for <br> elements in container', () => {
65+
it( 'returns null because container does not need the block filler', () => {
66+
expect( parse( '<container:p>Foo.</container:p>' ).getFillerOffset() ).to.equals( null );
67+
} );
68+
69+
it( 'returns offset of the last child which is the <br> element (1)', () => {
70+
expect( parse( '<container:p><empty:br></empty:br></container:p>' ).getFillerOffset() ).to.equals( 1 );
71+
} );
72+
73+
it( 'returns offset of the last child which is the <br> element (2)', () => {
74+
expect( parse( '<container:p>Foo.<empty:br></empty:br></container:p>' ).getFillerOffset() ).to.equals( 2 );
75+
} );
76+
77+
it( 'always returns the last <br> element in the container', () => {
78+
expect( parse( '<container:p>Foo.<empty:br></empty:br><empty:br></empty:br></container:p>' ).getFillerOffset() )
79+
.to.equals( 3 );
80+
} );
81+
82+
it( 'works fine with non-empty container with multi <br> elements', () => {
83+
expect( parse( '<container:p>Foo.<empty:br></empty:br>Bar.<empty:br></empty:br></container:p>' ).getFillerOffset() )
84+
.to.equals( 4 );
85+
} );
86+
87+
it( 'ignores the ui elements', () => {
88+
expect( parse( '<container:p><ui:span></ui:span><empty:br></empty:br></container:p>' ).getFillerOffset() )
89+
.to.equals( 2 );
90+
} );
91+
92+
it( 'empty element must be the <br> element', () => {
93+
expect( parse( '<container:p>Foo<empty:img></empty:img></container:p>' ).getFillerOffset() )
94+
.to.equals( null );
95+
} );
96+
} );
6297
} );
6398
} );

0 commit comments

Comments
 (0)