浏览代码

Refactor internal helpers in DocumentSelection#_fixGraveyardSelection.

Maciej Gołaszewski 5 年之前
父节点
当前提交
c8aef56523
共有 1 个文件被更改,包括 7 次插入13 次删除
  1. 7 13
      packages/ckeditor5-engine/src/model/documentselection.js

+ 7 - 13
packages/ckeditor5-engine/src/model/documentselection.js

@@ -1137,14 +1137,16 @@ class LiveSelection extends Selection {
 		liveRange.detach();
 		liveRange.detach();
 
 
 		// If nearest valid selection range has been found - add it in the place of old range.
 		// If nearest valid selection range has been found - add it in the place of old range.
-		if ( selectionRange && !isIntersecting( this._ranges, selectionRange ) ) {
+		// If range is intersecting with other selection ranges then it is probably due to contents
+		// of a multi-range selection being removed. See ckeditor/ckeditor5#6501.
+		if ( selectionRange && !isRangeIntersectingWithSelection( selectionRange, this ) ) {
 			// Check the range, convert it to live range, bind events, etc.
 			// Check the range, convert it to live range, bind events, etc.
 			const newRange = this._prepareRange( selectionRange );
 			const newRange = this._prepareRange( selectionRange );
 
 
 			// Add new range in the place of old range.
 			// Add new range in the place of old range.
 			this._ranges.splice( index, 0, newRange );
 			this._ranges.splice( index, 0, newRange );
 		}
 		}
-		// If nearest valid selection range cannot be found - just removing the old range is fine.
+		// If nearest valid selection range cannot be found or is intersecting with other selection ranges removing the old range is fine.
 	}
 	}
 }
 }
 
 
@@ -1164,7 +1166,6 @@ function getAttrsIfCharacter( node ) {
 
 
 // Removes selection attributes from element which is not empty anymore.
 // Removes selection attributes from element which is not empty anymore.
 //
 //
-// @private
 // @param {module:engine/model/model~Model} model
 // @param {module:engine/model/model~Model} model
 // @param {module:engine/model/batch~Batch} batch
 // @param {module:engine/model/batch~Batch} batch
 function clearAttributesStoredInElement( model, batch ) {
 function clearAttributesStoredInElement( model, batch ) {
@@ -1191,14 +1192,7 @@ function clearAttributesStoredInElement( model, batch ) {
 	}
 	}
 }
 }
 
 
-// Checks if range intersects with any given ranges.
-function isIntersecting( ranges, selectionRange ) {
-	for ( let i = 0; i < ranges.length; i++ ) {
-		if ( selectionRange.isIntersecting( ranges[ i ] ) ) {
-			// It is also fine - as we can have multiple ranges in the selection.
-			return true;
-		}
-	}
-
-	return false;
+// Checks if range intersects with any of selection ranges.
+function isRangeIntersectingWithSelection( range, selection ) {
+	return !selection._ranges.every( selectionRange => !range.isIntersecting( selectionRange ) );
 }
 }