@@ -1050,7 +1050,7 @@ function RemoteFunctions(config) {
10501050 let leftPos = offset . left + elemBounds . width - boxWidth ;
10511051
10521052 // Check if the box would go off the top of the viewport
1053- if ( offset . top - boxHeight < 0 ) {
1053+ if ( elemBounds . top - boxHeight < 6 ) {
10541054 topPos = offset . top + elemBounds . height + 6 ;
10551055 }
10561056
@@ -1305,7 +1305,7 @@ function RemoteFunctions(config) {
13051305 topPos = offset . top - boxDimensions . height - 6 ; // 6 for just some little space to breathe
13061306 leftPos = offset . left ;
13071307
1308- if ( offset . top - boxDimensions . height < 0 ) {
1308+ if ( elemBounds . top - boxDimensions . height < 6 ) {
13091309 topPos = offset . top + elemBounds . height + 6 ;
13101310 }
13111311
@@ -2096,15 +2096,45 @@ function RemoteFunctions(config) {
20962096 // Add a capture-phase scroll listener to update highlights when
20972097 // any element scrolls.
20982098
2099+
2100+ // Helper function to dismiss boxes only for elements that don't move with scroll
2101+ function _dismissBoxesForFixedElements ( ) {
2102+ if ( _nodeMoreOptionsBox && _nodeMoreOptionsBox . element ) {
2103+ // Store the element's position before scroll
2104+ if ( ! _nodeMoreOptionsBox . _lastPosition ) {
2105+ _nodeMoreOptionsBox . _lastPosition = _nodeMoreOptionsBox . element . getBoundingClientRect ( ) ;
2106+ return ; // First time, just store position
2107+ }
2108+
2109+ const currentPosition = _nodeMoreOptionsBox . element . getBoundingClientRect ( ) ;
2110+ const lastPosition = _nodeMoreOptionsBox . _lastPosition ;
2111+
2112+ // If element position hasn't changed despite scrolling, it's likely fixed/sticky
2113+ const positionUnchanged =
2114+ Math . abs ( currentPosition . top - lastPosition . top ) < 1 &&
2115+ Math . abs ( currentPosition . left - lastPosition . left ) < 1 ;
2116+
2117+ if ( positionUnchanged ) {
2118+ dismissMoreOptionsBox ( ) ;
2119+ } else {
2120+ // Update stored position for next scroll event
2121+ _nodeMoreOptionsBox . _lastPosition = currentPosition ;
2122+ }
2123+ }
2124+ }
2125+
20992126 function _scrollHandler ( e ) {
21002127 // Document scrolls can be updated immediately. Any other scrolls
21012128 // need to be updated on a timer to ensure the layout is correct.
21022129 if ( e . target === window . document ) {
21032130 redrawHighlights ( ) ;
2131+ // need to dismiss the box if the elements are fixed, otherwise they drift at times
2132+ _dismissBoxesForFixedElements ( ) ;
21042133 } else {
21052134 if ( _localHighlight || _clickHighlight || _hoverHighlight ) {
21062135 window . setTimeout ( redrawHighlights , 0 ) ;
21072136 }
2137+ _dismissBoxesForFixedElements ( ) ;
21082138 }
21092139 }
21102140
0 commit comments