Skip to content

Commit

Permalink
Optimize getVisibleElementBounds in scrollable cases (#66546)
Browse files Browse the repository at this point in the history
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
  • Loading branch information
3 people authored and gutenbergplugin committed Nov 5, 2024
1 parent c4e8df9 commit 65e6363
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions packages/block-editor/src/utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,14 @@ export function getVisibleElementBounds( element ) {
let currentElement;

while ( ( currentElement = stack.pop() ) ) {
for ( const child of currentElement.children ) {
if ( isElementVisible( child ) ) {
let childBounds = child.getBoundingClientRect();
// If the parent is scrollable, use parent's scrollable bounds.
if ( isScrollable( currentElement ) ) {
childBounds = currentElement.getBoundingClientRect();
// Children won’t affect bounds unless the element is not scrollable.
if ( ! isScrollable( currentElement ) ) {
for ( const child of currentElement.children ) {
if ( isElementVisible( child ) ) {
const childBounds = child.getBoundingClientRect();
bounds = rectUnion( bounds, childBounds );
stack.push( child );
}
bounds = rectUnion( bounds, childBounds );
stack.push( child );
}
}
}
Expand Down

0 comments on commit 65e6363

Please sign in to comment.