8
0
Pārlūkot izejas kodu

Introduced Position.getParentPath.

Piotr Jasiun 10 gadi atpakaļ
vecāks
revīzija
bdb481f6f1

+ 2 - 2
packages/ckeditor5-utils/src/document/moveoperation.js

@@ -99,8 +99,8 @@ CKEDITOR.define( [
 					{ moveOperation: this }
 				);
 			} else {
-				var sourcePath = this.sourcePosition.path.slice( 0, -1 );
-				var targetPath = this.targetPosition.path.slice( 0, -1 );
+				var sourcePath = this.sourcePosition.getParentPath();
+				var targetPath = this.targetPosition.getParentPath();
 
 				if ( utils.compareArrays( sourcePath, targetPath ) == utils.compareArrays.PREFIX ) {
 					var i = sourcePath.length;

+ 11 - 0
packages/ckeditor5-utils/src/document/position.js

@@ -157,6 +157,17 @@ CKEDITOR.define( [ 'utils', 'ckeditorerror' ], function( utils, CKEditorError )
 		isEqual( otherPosition ) {
 			return utils.isEqual( this.path, otherPosition.path );
 		}
+
+		/**
+		 * Return the path to the parent, which is the {@link document.Position#path} without the last element.
+		 *
+		 * This method return the parent path even if the parent does not exists.
+		 *
+		 * @returns {Array} Path to the parent.
+		 */
+		getParentPath() {
+			return this.path.slice( 0, -1 );
+		}
 	}
 
 	return Position;

+ 6 - 0
packages/ckeditor5-utils/tests/document/position.js

@@ -220,4 +220,10 @@ describe( 'position', function() {
 
 		expect( position.isEqual( differentNode ) ).to.be.false;
 	} );
+
+	it( 'should have proper parent path', function() {
+		var position = new Position( [ 1, 2, 3 ], root );
+
+		expect( position.getParentPath() ).to.deep.equal( [ 1, 2 ] );
+	} );
 } );