Skip to content

Commit 6719bf0

Browse files
committedDec 10, 2020
Merge branch 'feat/better-placeholder-behavior' of git://github.com/huacnlee/ckeditor5 into huacnlee-feat/better-placeholder-behavior
2 parents 0ad1d6a + a75f9df commit 6719bf0

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed
 

‎packages/ckeditor5-engine/src/view/placeholder.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,8 @@ export function needsPlaceholder( element ) {
152152
const isEmptyish = !Array.from( element.getChildren() )
153153
.some( element => !element.is( 'uiElement' ) );
154154

155-
const doc = element.document;
156-
157-
// If the element is empty and the document is blurred.
158-
if ( !doc.isFocused && isEmptyish ) {
159-
return true;
160-
}
161-
162-
const viewSelection = doc.selection;
163-
const selectionAnchor = viewSelection.anchor;
164-
165-
// If document is focused and the element is empty but the selection is not anchored inside it.
166-
if ( isEmptyish && selectionAnchor && selectionAnchor.parent !== element ) {
155+
// If the element, keep placeholder
156+
if ( isEmptyish ) {
167157
return true;
168158
}
169159

‎packages/ckeditor5-engine/tests/view/placeholder.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe( 'placeholder', () => {
9595
} );
9696

9797
expect( element.getAttribute( 'data-placeholder' ) ).to.equal( 'foo bar baz' );
98-
expect( element.hasClass( 'ck-placeholder' ) ).to.be.false;
98+
expect( element.hasClass( 'ck-placeholder' ) ).to.be.true;
9999
} );
100100

101101
it( 'if element has selection inside but document is blurred should contain placeholder CSS class', () => {
@@ -132,7 +132,7 @@ describe( 'placeholder', () => {
132132
writer.setSelection( ViewRange._createIn( element ) );
133133
} );
134134

135-
expect( element.hasClass( 'ck-placeholder' ) ).to.be.false;
135+
expect( element.hasClass( 'ck-placeholder' ) ).to.be.true;
136136
} );
137137

138138
it( 'should change placeholder settings when called twice', () => {
@@ -208,10 +208,10 @@ describe( 'placeholder', () => {
208208
} );
209209

210210
expect( element.getAttribute( 'data-placeholder' ) ).to.equal( 'first placeholder' );
211-
expect( element.hasClass( 'ck-placeholder' ) ).to.be.false;
211+
expect( element.hasClass( 'ck-placeholder' ) ).to.be.true;
212212

213213
expect( secondElement.getAttribute( 'data-placeholder' ) ).to.equal( 'second placeholder' );
214-
expect( secondElement.hasClass( 'ck-placeholder' ) ).to.be.false;
214+
expect( secondElement.hasClass( 'ck-placeholder' ) ).to.be.true;
215215
} );
216216

217217
it( 'should update placeholder before rendering', () => {
@@ -233,7 +233,7 @@ describe( 'placeholder', () => {
233233
} );
234234

235235
// After rendering - placeholder should be invisible since selection is moved there.
236-
expect( element.hasClass( 'ck-placeholder' ) ).to.be.false;
236+
expect( element.hasClass( 'ck-placeholder' ) ).to.be.true;
237237
} );
238238

239239
it( 'should not set attributes/class when multiple children (isDirectHost=false)', () => {

‎packages/ckeditor5-engine/theme/placeholder.css

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
.ck.ck-placeholder,
88
.ck .ck-placeholder {
99
&::before {
10+
position: absolute;
1011
content: attr(data-placeholder);
1112

1213
/* See ckeditor/ckeditor5#469. */

0 commit comments

Comments
 (0)
Please sign in to comment.