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

Changed multiple parameters to one object parameter in treeView.node.getAncestors.

Szymon Kupś 9 жил өмнө
parent
commit
411f78a8e8

+ 6 - 5
packages/ckeditor5-engine/src/treeview/node.js

@@ -108,17 +108,18 @@ export default class Node {
 	/**
 	/**
 	 * Returns ancestors array of this node.
 	 * Returns ancestors array of this node.
 	 *
 	 *
-	 * @param {Boolean} [includeNode=false] When set to `true` this node will be also included in parent's array.
-	 * @param {Boolean} [parentFirst=false] When set to `true`, array will be sorted from node's parent to root element,
+	 * @param {Object} options Options object.
+	 * @param {Boolean} [options.includeNode=false] When set to `true` this node will be also included in parent's array.
+	 * @param {Boolean} [options.parentFirst=false] When set to `true`, array will be sorted from node's parent to root element,
 	 * otherwise root element will be the first item in the array.
 	 * otherwise root element will be the first item in the array.
 	 * @returns {Array} Array with ancestors.
 	 * @returns {Array} Array with ancestors.
 	 */
 	 */
-	getAncestors( includeNode, parentFirst ) {
+	getAncestors( options = { includeNode: false, parentFirst: false } ) {
 		const ancestors = [];
 		const ancestors = [];
-		let parent = includeNode ? this : this.parent;
+		let parent = options.includeNode ? this : this.parent;
 
 
 		while ( parent !== null ) {
 		while ( parent !== null ) {
-			ancestors[ parentFirst ? 'push' : 'unshift' ]( parent );
+			ancestors[ options.parentFirst ? 'push' : 'unshift' ]( parent );
 			parent = parent.parent;
 			parent = parent.parent;
 		}
 		}
 
 

+ 2 - 2
packages/ckeditor5-engine/src/treeview/position.js

@@ -106,8 +106,8 @@ export default class Position {
 		}
 		}
 
 
 		// Get path from root to position's parent element.
 		// Get path from root to position's parent element.
-		const path = this.parent.getAncestors( true );
-		const otherPath = otherPosition.parent.getAncestors( true );
+		const path = this.parent.getAncestors( { includeNode: true } );
+		const otherPath = otherPosition.parent.getAncestors( { includeNode: true } );
 
 
 		// Compare both path arrays to find common ancestor.
 		// Compare both path arrays to find common ancestor.
 		const result = utils.compareArrays( path, otherPath );
 		const result = utils.compareArrays( path, otherPath );

+ 4 - 4
packages/ckeditor5-engine/tests/treeview/node.js

@@ -65,7 +65,7 @@ describe( 'Node', () => {
 		} );
 		} );
 
 
 		it( 'should return array including node itself if requested', () => {
 		it( 'should return array including node itself if requested', () => {
-			const result = root.getAncestors( true );
+			const result = root.getAncestors( { includeNode: true } );
 			expect( result ).to.be.an( 'array' );
 			expect( result ).to.be.an( 'array' );
 			expect( result.length ).to.equal( 1 );
 			expect( result.length ).to.equal( 1 );
 			expect( result[ 0 ] ).to.equal( root );
 			expect( result[ 0 ] ).to.equal( root );
@@ -77,7 +77,7 @@ describe( 'Node', () => {
 			expect( result[ 0 ] ).to.equal( root );
 			expect( result[ 0 ] ).to.equal( root );
 			expect( result[ 1 ] ).to.equal( two );
 			expect( result[ 1 ] ).to.equal( two );
 
 
-			const result2 = charR.getAncestors( true );
+			const result2 = charR.getAncestors( { includeNode: true } );
 			expect( result2.length ).to.equal( 3 );
 			expect( result2.length ).to.equal( 3 );
 			expect( result2[ 0 ] ).to.equal( root );
 			expect( result2[ 0 ] ).to.equal( root );
 			expect( result2[ 1 ] ).to.equal( two );
 			expect( result2[ 1 ] ).to.equal( two );
@@ -85,12 +85,12 @@ describe( 'Node', () => {
 		} );
 		} );
 
 
 		it( 'should return array of ancestors starting from parent', () => {
 		it( 'should return array of ancestors starting from parent', () => {
-			const result = charR.getAncestors( false, true );
+			const result = charR.getAncestors( { parentFirst: true } );
 			expect( result.length ).to.equal( 2 );
 			expect( result.length ).to.equal( 2 );
 			expect( result[ 0 ] ).to.equal( two );
 			expect( result[ 0 ] ).to.equal( two );
 			expect( result[ 1 ] ).to.equal( root );
 			expect( result[ 1 ] ).to.equal( root );
 
 
-			const result2 = charR.getAncestors( true, true );
+			const result2 = charR.getAncestors( { includeNode: true, parentFirst: true } );
 			expect( result2.length ).to.equal( 3 );
 			expect( result2.length ).to.equal( 3 );
 			expect( result2[ 2 ] ).to.equal( root );
 			expect( result2[ 2 ] ).to.equal( root );
 			expect( result2[ 1 ] ).to.equal( two );
 			expect( result2[ 1 ] ).to.equal( two );