Răsfoiți Sursa

Fix (utils): Fixed Rect results for sequenced range. Closes #7838.

Marek Lewandowski 5 ani în urmă
părinte
comite
0ed523ef12
1 a modificat fișierele cu 23 adăugiri și 1 ștergeri
  1. 23 1
      packages/ckeditor5-utils/src/dom/rect.js

+ 23 - 1
packages/ckeditor5-utils/src/dom/rect.js

@@ -78,7 +78,7 @@ export default class Rect {
 			// @if CK_DEBUG // }
 
 			if ( isSourceRange ) {
-				copyRectProperties( this, Rect.getDomRangeRects( source )[ 0 ] );
+				copyRangeRectProperties( this, source );
 			} else {
 				copyRectProperties( this, source.getBoundingClientRect() );
 			}
@@ -406,3 +406,25 @@ function isBody( elementOrRange ) {
 
 	return elementOrRange === elementOrRange.ownerDocument.body;
 }
+
+// Copies size properties from the `source` to the `rect`.
+//
+// @private
+// @param {module:utils/dom/rect~Rect} rect Target rect.
+// @param {Range} source
+function copyRangeRectProperties( rect, source ) {
+	const rangeRects = Rect.getDomRangeRects( source );
+	const combinedRect = rangeRects[ 0 ];
+
+	for ( let i = 1; i < rangeRects.length; i++ ) {
+		combinedRect.right = Math.max( combinedRect.right, rangeRects[ i ].right );
+		combinedRect.left = Math.min( combinedRect.left, rangeRects[ i ].left );
+		combinedRect.bottom = Math.max( combinedRect.bottom, rangeRects[ i ].bottom );
+		combinedRect.top = Math.min( combinedRect.top, rangeRects[ i ].top );
+	}
+
+	combinedRect.width = combinedRect.right - combinedRect.left;
+	combinedRect.height = combinedRect.bottom - combinedRect.top;
+
+	copyRectProperties( rect, combinedRect );
+}