8
0
Kuba Niegowski 5 лет назад
Родитель
Сommit
0ba73f20fc

+ 9 - 10
packages/ckeditor5-engine/src/model/range.js

@@ -277,9 +277,8 @@ export default class Range {
 	}
 
 	/**
-	 * Returns a sum of this {@link ~Range range} and given {@link ~Range range}.
-	 * Sum is a range that is spanning over both of those ranges. If ranges have no common part, returns `null`,
-	 * even if the ranges has equal start/end position.
+	 * Returns a range created by joining this {@link ~Range range} with the given {@link ~Range range}.
+	 * If ranges have no common part, returns `null`, even if they have equal start/end position.
 	 *
 	 * Examples:
 	 *
@@ -300,23 +299,23 @@ export default class Range {
 	 *		transformed = range.getJoined( otherRange ); // range from [ 2, 7 ] to [ 5 ]
 	 *
 	 * @param {module:engine/model/range~Range} otherRange Range to sum with.
-	 * @param {Boolean} [loose=false] Whether the sum intersection check is loose or strict. If the check is strict (`false`),
-	 * summed range is tested for intersection only. If the check is loose (`true`), compared range is also checked if it's "touching"
+	 * @param {Boolean} [loose=false] Whether the intersection check is loose or strict. If the check is strict (`false`),
+	 * ranges are tested for intersection only. If the check is loose (`true`), compared range is also checked if it's "touching"
 	 * current range.
 	 * @returns {module:engine/model/range~Range|null} A sum of given ranges or `null` if ranges have no common part.
 	 */
 	getJoined( otherRange, loose = false ) {
-		let shouldSum = this.isIntersecting( otherRange );
+		let shouldJoin = this.isIntersecting( otherRange );
 
-		if ( loose && !shouldSum ) {
+		if ( loose && !shouldJoin ) {
 			if ( this.start.isBefore( otherRange.start ) ) {
-				shouldSum = this.end.isTouching( otherRange.start );
+				shouldJoin = this.end.isTouching( otherRange.start );
 			} else {
-				shouldSum = otherRange.end.isTouching( this.start );
+				shouldJoin = otherRange.end.isTouching( this.start );
 			}
 		}
 
-		if ( !shouldSum ) {
+		if ( !shouldJoin ) {
 			return null;
 		}
 

+ 8 - 6
packages/ckeditor5-undo/src/basecommand.js

@@ -98,9 +98,7 @@ export default class BaseCommand extends Command {
 
 		for ( const rangeGroup of transformedRangeGroups ) {
 			// While transforming there could appear ranges that are contained by other ranges, we shall ignore them.
-			const transformed = rangeGroup.filter( range => !allRanges.some( otherRange => (
-				otherRange !== range && otherRange.containsRange( range, true )
-			) ) );
+			const transformed = rangeGroup.filter( range => !isRangeContainedByAnyOtherRange( range, allRanges ) );
 
 			// After the range got transformed, we have an array of ranges. Some of those
 			// ranges may be "touching" -- they can be next to each other and could be merged.
@@ -188,12 +186,16 @@ function normalizeRanges( ranges ) {
 
 	for ( let i = 1; i < ranges.length; i++ ) {
 		const previousRange = ranges[ i - 1 ];
-		const summedRange = previousRange.getJoined( ranges[ i ], true );
+		const joinedRange = previousRange.getJoined( ranges[ i ], true );
 
-		if ( summedRange ) {
+		if ( joinedRange ) {
 			// Replace the ranges on the list with the new joined range.
 			i--;
-			ranges.splice( i, 2, summedRange );
+			ranges.splice( i, 2, joinedRange );
 		}
 	}
 }
+
+function isRangeContainedByAnyOtherRange( range, ranges ) {
+	return ranges.some( otherRange => otherRange !== range && otherRange.containsRange( range, true ) );
+}