8
0
Эх сурвалжийг харах

Changed core.treeView.Element#same and core.treeView.Text#same methods names to isSimilar.

Szymon Kupś 9 жил өмнө
parent
commit
92197491ea

+ 3 - 3
packages/ckeditor5-engine/src/treeview/element.js

@@ -241,13 +241,13 @@ export default class Element extends Node {
 	}
 	}
 
 
 	/**
 	/**
-	 * Checks if this element is the same as other element.
-	 * Both elements should have the same name and attributes to be considered as same.
+	 * Checks if this element is similar to other element.
+	 * Both elements should have the same name and attributes to be considered as similar.
 	 *
 	 *
 	 * @param {Element} otherElement
 	 * @param {Element} otherElement
 	 * @returns {Boolean}
 	 * @returns {Boolean}
 	 */
 	 */
-	same( otherElement ) {
+	isSimilar( otherElement ) {
 		if ( !( otherElement instanceof Element ) ) {
 		if ( !( otherElement instanceof Element ) ) {
 			return false;
 			return false;
 		}
 		}

+ 1 - 1
packages/ckeditor5-engine/src/treeview/node.js

@@ -145,7 +145,7 @@ export default class Node {
 	/**
 	/**
 	 * Checks if provided node is the same as this node.
 	 * Checks if provided node is the same as this node.
 	 *
 	 *
-	 * @method treeView.Node#same
+	 * @method treeView.Node#isSimilar
 	 * @returns {Boolean} True if nodes are the same.
 	 * @returns {Boolean} True if nodes are the same.
 	 */
 	 */
 
 

+ 3 - 3
packages/ckeditor5-engine/src/treeview/text.js

@@ -58,13 +58,13 @@ export default class Text extends Node {
 	}
 	}
 
 
 	/**
 	/**
-	 * Checks if this text node is the same as other text node.
-	 * Both nodes should have the same data to be considered as same.
+	 * Checks if this text node is similar to other text node.
+	 * Both nodes should have the same data to be considered as similar.
 	 *
 	 *
 	 * @param {core.treeView.Text} otherNode Node to check if it is same as this node.
 	 * @param {core.treeView.Text} otherNode Node to check if it is same as this node.
 	 * @returns {Boolean}
 	 * @returns {Boolean}
 	 */
 	 */
-	same( otherNode ) {
+	isSimilar( otherNode ) {
 		if ( !( otherNode instanceof Text ) ) {
 		if ( !( otherNode instanceof Text ) ) {
 			return false;
 			return false;
 		}
 		}

+ 4 - 4
packages/ckeditor5-engine/src/treeview/writer.js

@@ -231,7 +231,7 @@ import CKEditorError from '../ckeditorerror.js';
 
 
 	/**
 	/**
 	 * Merges attribute nodes. It also merges text nodes if needed.
 	 * Merges attribute nodes. It also merges text nodes if needed.
-	 * Only {@link core.treeView.Element#same similar} `attribute` nodes, with same priority can be merged.
+	 * Only {@link core.treeView.Element#isSimilar similar} `attribute` nodes, with same priority can be merged.
 	 *
 	 *
 	 *		<p>{foo}|{bar}</p> -> <p>{foo|bar}</p>
 	 *		<p>{foo}|{bar}</p> -> <p>{foo|bar}</p>
 	 *		<p><b>{foo}</b>|<b>{bar}</b> -> <p><b>{foo|bar}</b></b>
 	 *		<p><b>{foo}</b>|<b>{bar}</b> -> <p><b>{foo|bar}</b></b>
@@ -272,7 +272,7 @@ import CKEditorError from '../ckeditorerror.js';
 			positionParent.removeChildren( positionOffset );
 			positionParent.removeChildren( positionOffset );
 
 
 			return new Position( nodeBefore, nodeBeforeLength );
 			return new Position( nodeBefore, nodeBeforeLength );
-		} else if ( nodeBefore.same( nodeAfter ) ) {
+		} else if ( nodeBefore.isSimilar( nodeAfter ) ) {
 			// When selection is between same nodes.
 			// When selection is between same nodes.
 			const nodeBeforePriority = this._priorities.get( nodeBefore );
 			const nodeBeforePriority = this._priorities.get( nodeBefore );
 			const nodeAfterPriority = this._priorities.get( nodeAfter );
 			const nodeAfterPriority = this._priorities.get( nodeAfter );
@@ -508,8 +508,8 @@ function unwrapChildren( writer, parent, startOffset, endOffset, attribute ) {
 	while ( i < endOffset ) {
 	while ( i < endOffset ) {
 		const child = parent.getChild( i );
 		const child = parent.getChild( i );
 
 
-		// If attributes are the same and have same priority, then unwrap.
-		if (  child.same( attribute ) && writer.getPriority( child ) == writer.getPriority( attribute ) ) {
+		// If attributes are the similar and have same priority, then unwrap.
+		if (  child.isSimilar( attribute ) && writer.getPriority( child ) == writer.getPriority( attribute ) ) {
 			const unwrapped = child.getChildren();
 			const unwrapped = child.getChildren();
 			const count = child.getChildCount();
 			const count = child.getChildCount();
 
 

+ 9 - 10
packages/ckeditor5-engine/tests/treeview/element.js

@@ -103,28 +103,27 @@ describe( 'Element', () => {
 		} );
 		} );
 	} );
 	} );
 
 
-	describe( 'same', () => {
+	describe( 'isSimilar', () => {
 		const el = new ViewElement( 'p', { foo: 'bar' } );
 		const el = new ViewElement( 'p', { foo: 'bar' } );
-
 		it( 'should return false when comparing to non-element', () => {
 		it( 'should return false when comparing to non-element', () => {
-			expect( el.same( null ) ).to.be.false;
-			expect( el.same( {} ) ).to.be.false;
+			expect( el.isSimilar( null ) ).to.be.false;
+			expect( el.isSimilar( {} ) ).to.be.false;
 		} );
 		} );
 
 
 		it( 'should return true when the same node is provided', () => {
 		it( 'should return true when the same node is provided', () => {
-			expect( el.same( el ) ).to.be.true;
+			expect( el.isSimilar( el ) ).to.be.true;
 		} );
 		} );
 
 
 		it( 'should return true for element with same attributes and name', () => {
 		it( 'should return true for element with same attributes and name', () => {
 			const other = new ViewElement( 'p', { foo: 'bar' } );
 			const other = new ViewElement( 'p', { foo: 'bar' } );
-			expect( el.same( other ) ).to.be.true;
+			expect( el.isSimilar( other ) ).to.be.true;
 		} );
 		} );
 
 
 		it( 'sould return false when name is not the same', () => {
 		it( 'sould return false when name is not the same', () => {
 			const other = el.clone();
 			const other = el.clone();
 			other.name = 'div';
 			other.name = 'div';
 
 
-			expect( el.same( other ) ).to.be.false;
+			expect( el.isSimilar( other ) ).to.be.false;
 		} );
 		} );
 
 
 		it( 'should return false when attributes are not the same', () => {
 		it( 'should return false when attributes are not the same', () => {
@@ -134,9 +133,9 @@ describe( 'Element', () => {
 			other1.setAttribute( 'baz', 'qux' );
 			other1.setAttribute( 'baz', 'qux' );
 			other2.setAttribute( 'foo', 'not-bar' );
 			other2.setAttribute( 'foo', 'not-bar' );
 			other3.removeAttribute( 'foo' );
 			other3.removeAttribute( 'foo' );
-			expect( el.same( other1 ) ).to.be.false;
-			expect( el.same( other2 ) ).to.be.false;
-			expect( el.same( other3 ) ).to.be.false;
+			expect( el.isSimilar( other1 ) ).to.be.false;
+			expect( el.isSimilar( other2 ) ).to.be.false;
+			expect( el.isSimilar( other3 ) ).to.be.false;
 		} );
 		} );
 	} );
 	} );
 
 

+ 6 - 6
packages/ckeditor5-engine/tests/treeview/text.js

@@ -31,29 +31,29 @@ describe( 'Element', () => {
 		} );
 		} );
 	} );
 	} );
 
 
-	describe( 'same', () => {
+	describe( 'isSimilar', () => {
 		const text = new ViewText( 'foo' );
 		const text = new ViewText( 'foo' );
 
 
 		it( 'should return false when comparing to non-text', () => {
 		it( 'should return false when comparing to non-text', () => {
-			expect( text.same( null ) ).to.be.false;
-			expect( text.same( {} ) ).to.be.false;
+			expect( text.isSimilar( null ) ).to.be.false;
+			expect( text.isSimilar( {} ) ).to.be.false;
 		} );
 		} );
 
 
 		it( 'should return true when the same text node is provided', () => {
 		it( 'should return true when the same text node is provided', () => {
-			expect( text.same( text ) ).to.be.true;
+			expect( text.isSimilar( text ) ).to.be.true;
 		} );
 		} );
 
 
 		it( 'sould return true when data is the same', () => {
 		it( 'sould return true when data is the same', () => {
 			const other = new ViewText( 'foo' );
 			const other = new ViewText( 'foo' );
 
 
-			expect( text.same( other ) ).to.be.true;
+			expect( text.isSimilar( other ) ).to.be.true;
 		} );
 		} );
 
 
 		it( 'sould return false when data is not the same', () => {
 		it( 'sould return false when data is not the same', () => {
 			const other = text.clone();
 			const other = text.clone();
 			other.data = 'not-foo';
 			other.data = 'not-foo';
 
 
-			expect( text.same( other ) ).to.be.false;
+			expect( text.isSimilar( other ) ).to.be.false;
 		} );
 		} );
 	} );
 	} );