@@ -62,14 +62,15 @@ function selectMaestroScrollableViewport(
6262 direction : MaestroDirection ,
6363 platform : MaestroPlatform ,
6464) : Rect | undefined {
65- const applicationViewport = findLargestViewportRect ( snapshot . nodes ) ;
66- if ( ! applicationViewport || ! isPositiveFiniteRect ( applicationViewport ) ) return undefined ;
6765 const vertical = direction === 'up' || direction === 'down' ;
6866 const scrollable = filterVisibleMaestroMatches ( {
6967 nodes : snapshot . nodes ,
7068 matches : snapshot . nodes . filter ( ( node ) => isScrollableSnapshotType ( node . type ) ) ,
7169 platform,
7270 } ) ;
71+ const applicationViewport =
72+ findLargestViewportRect ( snapshot . nodes ) ?? findLargestPositiveRect ( scrollable ) ;
73+ if ( ! applicationViewport || ! isPositiveFiniteRect ( applicationViewport ) ) return undefined ;
7374 const candidates = scrollable . flatMap ( ( node ) => {
7475 if ( ! isPositiveFiniteRect ( node . rect ) ) return [ ] ;
7576 const viewport = intersectRects ( node . rect , applicationViewport ) ;
@@ -95,6 +96,21 @@ function selectMaestroScrollableViewport(
9596 return candidates . sort ( compareViewportAreaDescending ) [ 0 ] ?. viewport ;
9697}
9798
99+ function findLargestPositiveRect (
100+ nodes : readonly SnapshotState [ 'nodes' ] [ number ] [ ] ,
101+ ) : Rect | undefined {
102+ let largest : Rect | undefined ;
103+ for ( const node of nodes ) {
104+ if (
105+ isPositiveFiniteRect ( node . rect ) &&
106+ ( ! largest || node . rect . width * node . rect . height > largest . width * largest . height )
107+ ) {
108+ largest = node . rect ;
109+ }
110+ }
111+ return largest ;
112+ }
113+
98114function intersectRects ( left : Rect , right : Rect ) : Rect | undefined {
99115 const x = Math . max ( left . x , right . x ) ;
100116 const y = Math . max ( left . y , right . y ) ;
0 commit comments