瀏覽代碼

Position.parentPath to Position.getParentPath().

Szymon Cofalik 10 年之前
父節點
當前提交
e894065a1c

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

@@ -87,11 +87,8 @@ CKEDITOR.define( [
 					'operation-move-range-into-itself: Trying to move a range of nodes to the inside of that range.'
 				);
 			} else {
-				const sourcePath = this.sourcePosition.parentPath;
-				const targetPath = this.targetPosition.parentPath;
-
-				if ( utils.compareArrays( sourcePath, targetPath ) == utils.compareArrays.PREFIX ) {
-					let i = sourcePath.length;
+				if ( utils.compareArrays( this.sourcePosition.getParentPath(), this.targetPosition.getParentPath() ) == utils.compareArrays.PREFIX ) {
+					let i = this.sourcePosition.path.length - 1;
 
 					if ( this.targetPosition.path[ i ] >= sourceOffset && this.targetPosition.path[ i ] < sourceOffset + this.howMany ) {
 						/**

+ 8 - 8
packages/ckeditor5-utils/src/document/position.js

@@ -180,7 +180,7 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
 		 *
 		 * @returns {Number[]} Path to the parent.
 		 */
-		get parentPath() {
+		getParentPath() {
 			return this.path.slice( 0, -1 );
 		}
 
@@ -311,7 +311,7 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
 		 * @returns {document.Position} Combined position.
 		 */
 		getCombined( from, to ) {
-			const i = from.parentPath.length;
+			const i = from.path.length - 1;
 
 			// The first part of a path to combined position is a path to the place where nodes were moved.
 			let combined = to.clone();
@@ -346,16 +346,16 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
 				return transformed;
 			}
 
-			if ( utils.compareArrays( insertPosition.parentPath, this.parentPath ) == utils.compareArrays.SAME ) {
+			if ( utils.compareArrays( insertPosition.getParentPath(), this.getParentPath() ) == utils.compareArrays.SAME ) {
 				// If nodes are inserted in the node that is pointed by this position...
 				if ( insertPosition.offset < this.offset || ( insertPosition.offset == this.offset && insertBefore ) ) {
 					// And are inserted before an offset of that position...
 					// "Push" this positions offset.
 					transformed.offset += howMany;
 				}
-			} else if ( utils.compareArrays( insertPosition.parentPath, this.parentPath ) == utils.compareArrays.PREFIX ) {
+			} else if ( utils.compareArrays( insertPosition.getParentPath(), this.getParentPath() ) == utils.compareArrays.PREFIX ) {
 				// If nodes are inserted in a node that is on a path to this position...
-				const i = insertPosition.parentPath.length;
+				const i = insertPosition.path.length - 1;
 
 				if ( insertPosition.offset <= this.path[ i ] ) {
 					// And are inserted before next node of that path...
@@ -383,7 +383,7 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
 				return transformed;
 			}
 
-			if ( utils.compareArrays( deletePosition.parentPath, this.parentPath ) == utils.compareArrays.SAME ) {
+			if ( utils.compareArrays( deletePosition.getParentPath(), this.getParentPath() ) == utils.compareArrays.SAME ) {
 				// If nodes are removed from the node that is pointed by this position...
 				if ( deletePosition.offset < this.offset ) {
 					// And are removed from before an offset of that position...
@@ -394,9 +394,9 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
 						transformed.offset -= howMany;
 					}
 				}
-			} else if ( utils.compareArrays( deletePosition.parentPath, this.parentPath ) == utils.compareArrays.PREFIX ) {
+			} else if ( utils.compareArrays( deletePosition.getParentPath(), this.getParentPath() ) == utils.compareArrays.PREFIX ) {
 				// If nodes are removed from a node that is on a path to this position...
-				const i = deletePosition.parentPath.length;
+				const i = deletePosition.path.length - 1;
 
 				if ( deletePosition.offset < this.path[ i ] ) {
 					// And are removed from before next node of that path...

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

@@ -115,8 +115,8 @@ CKEDITOR.define( [ 'document/position', 'document/positioniterator', 'utils' ],
 		 */
 		getTransformedByInsertion( insertPosition, howMany, spreadOnlyOnSameLevel ) {
 			// Flag indicating whether this whole range and given insertPosition is on the same tree level.
-			const areOnSameLevel = utils.compareArrays( this.start.parentPath, this.end.parentPath ) == utils.compareArrays.SAME &&
-				utils.compareArrays( this.start.parentPath, insertPosition.parentPath ) == utils.compareArrays.SAME;
+			const areOnSameLevel = utils.compareArrays( this.start.getParentPath(), this.end.getParentPath() ) == utils.compareArrays.SAME &&
+				utils.compareArrays( this.start.getParentPath(), insertPosition.getParentPath() ) == utils.compareArrays.SAME;
 
 			if ( this.containsPosition( insertPosition ) && ( !spreadOnlyOnSameLevel || areOnSameLevel ) ) {
 				// Range has to be spread. The first part is from original start to the spread point.

+ 4 - 2
packages/ckeditor5-utils/src/document/transformoperation.js

@@ -366,8 +366,10 @@ CKEDITOR.define( [
 				// * on deeper tree level - it means that we move nodes that are inside moved nodes
 				// The operations are conflicting only if they try to move exactly same nodes, so only in the first case.
 				// So, we will handle common range if it is "deeper" or if transformed operation is more important.
-				if ( utils.compareArrays( b.sourcePosition.parentPath, a.sourcePosition.parentPath ) == utils.compareArrays.PREFIX || isStrong ) {
-					const common = rangeA.getCommon( rangeB );
+				let isDeeper = utils.compareArrays( b.sourcePosition.getParentPath(), a.sourcePosition.getParentPath() ) == utils.compareArrays.PREFIX;
+
+				if ( isDeeper || isStrong ) {
+					const common = rangeA.getIntersection( rangeB );
 
 					if ( common !== null ) {
 						// We substitute original position by the combination of target position and original position.

+ 2 - 2
packages/ckeditor5-utils/tests/document/position.js

@@ -243,10 +243,10 @@ describe( 'position', () => {
 		expect( position.isEqual( differentPosition ) ).to.be.false;
 	} );
 
-	it( 'should have correct parent path property', () => {
+	it( 'should have proper parent path', () => {
 		let position = new Position( [ 1, 2, 3 ], root );
 
-		expect( position.parentPath ).to.deep.equal( [ 1, 2 ] );
+		expect( position.getParentPath() ).to.deep.equal( [ 1, 2 ] );
 	} );
 
 	it( 'should return a new, equal position when cloned', () => {