@@ -62,6 +62,7 @@ window.getIsScrolledToContent = function () {
6262window . setIsScrolledToContent  =  function  ( value )  { 
6363    if  ( isScrolledToContent  !=  value )  { 
6464        isScrolledToContent  =  value ; 
65+         console . log ( `isScrolledToContent=${ isScrolledToContent }  ) ; 
6566    } 
6667} 
6768
@@ -82,17 +83,30 @@ window.initializeContinuousScroll = function () {
8283
8384    // The scroll event is used to detect when the user scrolls to view content. 
8485    container . addEventListener ( 'scroll' ,  ( )  =>  { 
85-         var  v  =  ! isScrolledToBottom ( container ) ; 
86-         setIsScrolledToContent ( v ) ; 
86+         var  atBottom  =  isScrolledToBottom ( container ) ; 
87+         if  ( atBottom  ===  null )  { 
88+             return ; 
89+         } 
90+         setIsScrolledToContent ( ! atBottom ) ; 
8791   } ,  {  passive : true  } ) ; 
8892
8993    // The ResizeObserver reports changes in the grid size. 
9094    // This ensures that the logs are scrolled to the bottom when there are new logs 
9195    // unless the user has scrolled to view content. 
9296    const  observer  =  new  ResizeObserver ( function  ( )  { 
9397        lastScrollHeight  =  container . scrollHeight ; 
94-         if  ( ! getIsScrolledToContent ( ) )  { 
98+ 
99+         if  ( lastScrollHeight  ==  container . clientHeight )  { 
100+             // There is no scrollbar. This could be because there's no content, or the content might have been cleared. 
101+             // Reset to default behavior: scroll to bottom 
102+             setIsScrolledToContent ( false ) ; 
103+             return ; 
104+         } 
105+ 
106+         var  isScrolledToContent  =  getIsScrolledToContent ( ) ; 
107+         if  ( ! isScrolledToContent )  { 
95108            container . scrollTop  =  lastScrollHeight ; 
109+             return ; 
96110        } 
97111    } ) ; 
98112    for  ( const  child  of  container . children )  { 
@@ -108,14 +122,18 @@ function isScrolledToBottom(container) {
108122    if  ( ! getIsScrolledToContent ( ) )  { 
109123        if  ( lastScrollHeight  !=  container . scrollHeight )  { 
110124            console . log ( `lastScrollHeight ${ lastScrollHeight } ${ container . scrollHeight }  ) ; 
125+ 
126+             // Unknown because the container size changed. 
127+             return  null ; 
111128        } 
112129    } 
113130
114131    const  marginOfError  =  5 ; 
115132    const  containerScrollBottom  =  lastScrollHeight  -  container . clientHeight ; 
116133    const  difference  =  containerScrollBottom  -  container . scrollTop ; 
117134
118-     return  difference  <  marginOfError ; 
135+     var  atBottom  =  difference  <  marginOfError ; 
136+     return  atBottom ; 
119137} 
120138
121139window . buttonOpenLink  =  function  ( element )  { 
0 commit comments