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

Commit 7c014f7

Browse files
authored
Merge pull request #1023 from ckeditor/t/1021
Fixed: Block filler was rendered before UI elements, interfering with their positioning. Now it will be properly rendered at the end of an element. Closes #1021.
2 parents b07b993 + ce800c4 commit 7c014f7

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

src/view/attributeelement.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ function getFillerOffset() {
120120
return null;
121121
}
122122

123-
return 0;
123+
// Render block filler at the end of element (after all ui elements).
124+
return this.childCount;
124125
}
125126

126127
// Returns total count of children that are not {@link module:engine/view/uielement~UIElement UIElements}.

src/view/containerelement.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,13 @@ export default class ContainerElement extends Element {
7878
//
7979
// @returns {Number|null} Block filler offset or `null` if block filler is not needed.
8080
function getFillerOffset() {
81-
return Array.from( this.getChildren() ).some( element => !element.is( 'uiElement' ) ) ? null : 0;
81+
for ( const child of this.getChildren() ) {
82+
// If there's any non-UI element – don't render the bogus.
83+
if ( !child.is( 'uiElement' ) ) {
84+
return null;
85+
}
86+
}
87+
88+
// If there are only UI elements – render the bogus at the end of the element.
89+
return this.childCount;
8290
}

tests/view/attributeelement.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,19 @@ describe( 'AttributeElement', () => {
138138
expect( attribute.getFillerOffset() ).to.be.null;
139139
} );
140140

141-
it( 'should return position 0 if it is the only nested element in the container and has UIElement inside', () => {
141+
it( 'should return offset after all children if it is the only nested element in the container and has UIElement inside', () => {
142142
const { selection } = parse(
143143
'<container:p><attribute:b><attribute:i>[]<ui:span></ui:span></attribute:i></attribute:b></container:p>' );
144144
const attribute = selection.getFirstPosition().parent;
145145

146-
expect( attribute.getFillerOffset() ).to.equals( 0 );
146+
expect( attribute.getFillerOffset() ).to.equal( 1 );
147147
} );
148148

149-
it( 'should return 0 if there is no parent container element and has UIElement inside', () => {
150-
const { selection } = parse( '<attribute:b>[]<ui:span></ui:span></attribute:b>' );
149+
it( 'should return offset after all children if there is no parent container element and has UIElement inside', () => {
150+
const { selection } = parse( '<attribute:b>[]<ui:span></ui:span><ui:span></ui:span></attribute:b>' );
151151
const attribute = selection.getFirstPosition().parent;
152152

153-
expect( attribute.getFillerOffset() ).to.equal( 0 );
153+
expect( attribute.getFillerOffset() ).to.equal( 2 );
154154
} );
155155
} );
156156
} );

tests/view/containerelement.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ describe( 'ContainerElement', () => {
5252
expect( parse( '<container:p></container:p>' ).getFillerOffset() ).to.equals( 0 );
5353
} );
5454

55-
it( 'should return position 0 if element contains only ui elements', () => {
56-
expect( parse( '<container:p><ui:span></ui:span></container:p>' ).getFillerOffset() ).to.equals( 0 );
55+
it( 'should return offset after all children if element contains only ui elements', () => {
56+
expect( parse( '<container:p><ui:span></ui:span><ui:span></ui:span></container:p>' ).getFillerOffset() ).to.equals( 2 );
5757
} );
5858

5959
it( 'should return null if element is not empty', () => {

tests/view/manual/uielement.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
font-size: 8px;
1313
border-top: 1px solid #dadada;
1414
font-family: sans-serif;
15-
}
16-
17-
.ui-element span {
1815
background-color: #7a7a7a;
1916
color: white;
2017
padding: 1px 5px;
18+
display: inline-block;
2119
}
2220
</style>
2321
<div id="container">

tests/view/manual/uielement.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class MyUIElement extends UIElement {
1919

2020
root.setAttribute( 'contenteditable', 'false' );
2121
root.classList.add( 'ui-element' );
22-
root.innerHTML = '<span>END OF PARAGRAPH</span>';
22+
root.innerHTML = 'END OF PARAGRAPH';
2323

2424
return root;
2525
}
@@ -33,7 +33,7 @@ class UIElementTestPlugin extends Plugin {
3333
// Add some UIElement to each paragraph.
3434
editing.modelToView.on( 'insert:paragraph', ( evt, data, consumable, conversionApi ) => {
3535
const viewP = conversionApi.mapper.toViewElement( data.item );
36-
viewP.appendChildren( new MyUIElement( 'div' ) );
36+
viewP.appendChildren( new MyUIElement( 'span' ) );
3737
}, { priority: 'lowest' } );
3838
}
3939
}

0 commit comments

Comments
 (0)