Browse Source

startsWithFiller should returns null for the element.

Piotr Jasiun 9 years ago
parent
commit
b02c8b1f88

+ 5 - 4
packages/ckeditor5-engine/src/view/filler.js

@@ -77,17 +77,18 @@ for ( let i = 0; i < INLINE_FILLER_LENGTH; i++ ) {
 }
 
 /**
- * Checks if the text node starts with the {@link engine.view.filler.INLINE_FILLER inline filler}.
+ * Checks if the node is a text node which starts with the {@link engine.view.filler.INLINE_FILLER inline filler}.
  *
  *		startsWithFiller( document.createTextNode( INLINE_FILLER ) ); // true
  *		startsWithFiller( document.createTextNode( INLINE_FILLER + 'foo' ) ); // true
  *		startsWithFiller( document.createTextNode( 'foo' ) ); // false
+ *		startsWithFiller( document.createElement( 'p' ) ); // false
  *
- * @param {Text} domText DOM text node.
+ * @param {Node} domNode DOM node.
  * @returns {Boolean} True if the text node starts with the {@link engine.view.filler.INLINE_FILLER inline filler}.
  */
-export function startsWithFiller( domText ) {
-	return ( domText.data.substr( 0, INLINE_FILLER_LENGTH ) === INLINE_FILLER );
+export function startsWithFiller( domNode ) {
+	return ( domNode instanceof Text ) && ( domNode.data.substr( 0, INLINE_FILLER_LENGTH ) === INLINE_FILLER );
 }
 
 /**

+ 8 - 2
packages/ckeditor5-engine/tests/view/filler.js

@@ -26,18 +26,24 @@ describe( 'filler', () => {
 	} );
 
 	describe( 'startsWithFiller', () => {
-		it( 'should be true for element which contains only filler', () => {
+		it( 'should be true for node which contains only filler', () => {
 			const node = document.createTextNode( INLINE_FILLER );
 
 			expect( startsWithFiller( node ) ).to.be.true;
 		} );
 
-		it( 'should be true for element which starts with filler', () => {
+		it( 'should be true for node which starts with filler', () => {
 			const node = document.createTextNode( INLINE_FILLER + 'foo' );
 
 			expect( startsWithFiller( node ) ).to.be.true;
 		} );
 
+		it( 'should be false for element', () => {
+			const node = document.createElement( 'p' );
+
+			expect( startsWithFiller( node ) ).to.be.false;
+		} );
+
 		it( 'should be false which contains filler in the middle', () => {
 			const node = document.createTextNode( 'x' + INLINE_FILLER + 'x' );