Skip to content

Commit

Permalink
Fix (utils): Fixed Rect results for sequenced range. Closes #7838.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlewand committed Aug 13, 2020
1 parent 0de3045 commit 0ed523e
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion packages/ckeditor5-utils/src/dom/rect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
Expand Down Expand Up @@ -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 );
}

0 comments on commit 0ed523e

Please sign in to comment.