Browse Source

Merge pull request #1502 from dimaip/patch-1

Fix: `startsWithFiller` should correctly work with DOM `Text` nodes that are inside of an iframe.

Huge thanks to [Dmitri Pisarev](https://github.com/dimaip) for this contribution!
Szymon Cofalik 7 years ago
parent
commit
f554c435fe

+ 3 - 2
packages/ckeditor5-engine/src/view/filler.js

@@ -3,9 +3,10 @@
  * For licensing, see LICENSE.md.
  */
 
-/* globals window, Text */
+/* globals window */
 
 import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
+import isText from '@ckeditor/ckeditor5-utils/src/dom/istext';
 
 /**
  * Set of utils related to block and inline fillers handling.
@@ -84,7 +85,7 @@ for ( let i = 0; i < INLINE_FILLER_LENGTH; i++ ) {
  * @returns {Boolean} True if the text node starts with the {@link module:engine/view/filler~INLINE_FILLER inline filler}.
  */
 export function startsWithFiller( domNode ) {
-	return ( domNode instanceof Text ) && ( domNode.data.substr( 0, INLINE_FILLER_LENGTH ) === INLINE_FILLER );
+	return isText( domNode ) && ( domNode.data.substr( 0, INLINE_FILLER_LENGTH ) === INLINE_FILLER );
 }
 
 /**

+ 10 - 0
packages/ckeditor5-engine/tests/view/filler.js

@@ -111,6 +111,16 @@ describe( 'filler', () => {
 
 			expect( isInlineFiller( node ) ).to.be.false;
 		} );
+
+		it( 'should be true for inline filler from inside iframe', () => {
+			const iframe = document.createElement( 'iframe' );
+			document.body.appendChild( iframe );
+			const node = iframe.contentDocument.createTextNode( INLINE_FILLER );
+
+			expect( isInlineFiller( node ) ).to.be.true;
+
+			document.body.removeChild( iframe );
+		} );
 	} );
 
 	describe( 'isBlockFiller', () => {