Sfoglia il codice sorgente

Aligned code to introduced isText() method.

Maciej Bukowski 7 anni fa
parent
commit
59d5efde2e

+ 7 - 16
packages/ckeditor5-engine/src/view/domconverter.js

@@ -22,6 +22,7 @@ import global from '@ckeditor/ckeditor5-utils/src/dom/global';
 import indexOf from '@ckeditor/ckeditor5-utils/src/dom/indexof';
 import getAncestors from '@ckeditor/ckeditor5-utils/src/dom/getancestors';
 import getCommonAncestor from '@ckeditor/ckeditor5-utils/src/dom/getcommonancestor';
+import isText from '@ckeditor/ckeditor5-utils/src/dom/istext';
 
 /**
  * DomConverter is a set of tools to do transformations between DOM nodes and view nodes. It also handles
@@ -339,7 +340,7 @@ export default class DomConverter {
 
 			// If there is an inline filler at position return position inside the filler. We should never return
 			// the position before the inline filler.
-			if ( this.isText( domAfter ) && startsWithFiller( domAfter ) ) {
+			if ( isText( domAfter ) && startsWithFiller( domAfter ) ) {
 				return { parent: domAfter, offset: INLINE_FILLER_LENGTH };
 			}
 
@@ -375,7 +376,7 @@ export default class DomConverter {
 			return uiElement;
 		}
 
-		if ( this.isText( domNode ) ) {
+		if ( isText( domNode ) ) {
 			if ( isInlineFiller( domNode ) ) {
 				return null;
 			} else {
@@ -460,7 +461,7 @@ export default class DomConverter {
 			let container = domSelection.getRangeAt( 0 ).startContainer;
 
 			// The DOM selection might be moved to the text node inside the fake selection container.
-			if ( this.isText( container ) ) {
+			if ( isText( container ) ) {
 				container = container.parentNode;
 			}
 
@@ -533,7 +534,7 @@ export default class DomConverter {
 			return ViewPosition.createBefore( viewElement );
 		}
 
-		if ( this.isText( domParent ) ) {
+		if ( isText( domParent ) ) {
 			if ( isInlineFiller( domParent ) ) {
 				return this.domPositionToView( domParent.parentNode, indexOf( domParent ) );
 			}
@@ -562,7 +563,7 @@ export default class DomConverter {
 				}
 			} else {
 				const domBefore = domParent.childNodes[ domOffset - 1 ];
-				const viewBefore = this.isText( domBefore ) ?
+				const viewBefore = isText( domBefore ) ?
 					this.findCorrespondingViewText( domBefore ) :
 					this.mapDomToView( domBefore );
 
@@ -750,16 +751,6 @@ export default class DomConverter {
 	}
 
 	/**
-	 * Returns `true` when `node.nodeType` equals `Node.TEXT_NODE`.
-	 *
-	 * @param {Node} node Node to check.
-	 * @returns {Boolean}
-	 */
-	isText( node ) {
-		return node && node.nodeType == Node.TEXT_NODE;
-	}
-
-	/**
 	 * Returns `true` when `node.nodeType` equals `Node.ELEMENT_NODE`.
 	 *
 	 * @param {Node} node Node to check.
@@ -864,7 +855,7 @@ export default class DomConverter {
 	 */
 	_isDomSelectionPositionCorrect( domParent, offset ) {
 		// If selection is before or in the middle of inline filler string, it is incorrect.
-		if ( this.isText( domParent ) && startsWithFiller( domParent ) && offset < INLINE_FILLER_LENGTH ) {
+		if ( isText( domParent ) && startsWithFiller( domParent ) && offset < INLINE_FILLER_LENGTH ) {
 			// Selection in a text node, at wrong position (before or in the middle of filler).
 			return false;
 		}

+ 4 - 3
packages/ckeditor5-engine/src/view/renderer.js

@@ -17,6 +17,7 @@ import insertAt from '@ckeditor/ckeditor5-utils/src/dom/insertat';
 import remove from '@ckeditor/ckeditor5-utils/src/dom/remove';
 import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+import isText from '@ckeditor/ckeditor5-utils/src/dom/istext';
 
 /**
  * Renderer updates DOM structure and selection, to make them a reflection of the view structure and selection.
@@ -256,7 +257,7 @@ export default class Renderer {
 		const childNodes = domParentOrArray instanceof Array ? domParentOrArray : domParentOrArray.childNodes;
 		const nodeAfterFiller = childNodes[ offset ];
 
-		if ( this.domConverter.isText( nodeAfterFiller ) ) {
+		if ( isText( nodeAfterFiller ) ) {
 			nodeAfterFiller.data = INLINE_FILLER + nodeAfterFiller.data;
 
 			return nodeAfterFiller;
@@ -321,7 +322,7 @@ export default class Renderer {
 		const selectionPosition = this.selection.getFirstPosition();
 		const position = this.domConverter.viewPositionToDom( selectionPosition );
 
-		if ( position && this.domConverter.isText( position.parent ) && startsWithFiller( position.parent ) ) {
+		if ( position && isText( position.parent ) && startsWithFiller( position.parent ) ) {
 			return true;
 		}
 
@@ -515,7 +516,7 @@ export default class Renderer {
 				return true;
 			}
 			// Texts.
-			else if ( domConverter.isText( actualDomChild ) && domConverter.isText( expectedDomChild ) ) {
+			else if ( isText( actualDomChild ) && isText( expectedDomChild ) ) {
 				return actualDomChild.data === expectedDomChild.data;
 			}
 			// Block fillers.

+ 0 - 13
packages/ckeditor5-engine/tests/view/domconverter/domconverter.js

@@ -143,19 +143,6 @@ describe( 'DomConverter', () => {
 			comment = document.createComment( 'a' );
 		} );
 
-		describe( 'isText()', () => {
-			it( 'should return true for Text nodes', () => {
-				expect( converter.isText( text ) ).to.be.true;
-			} );
-
-			it( 'should return false for other arguments', () => {
-				expect( converter.isText( element ) ).to.be.false;
-				expect( converter.isText( documentFragment ) ).to.be.false;
-				expect( converter.isText( comment ) ).to.be.false;
-				expect( converter.isText( {} ) ).to.be.false;
-			} );
-		} );
-
 		describe( 'isElement()', () => {
 			it( 'should return true for HTMLElement nodes', () => {
 				expect( converter.isElement( element ) ).to.be.true;