@@ -10,26 +10,39 @@ public void OnScrollChanged_ContentGrowsFasterThanScrollToEndCanCatchUp_StaysAut
1010 {
1111 var tracker = new AutoScrollTracker ( ) ;
1212
13- // Simulates a burst of fast-arriving log lines: new content arrives, so the caller asks
14- // whether it should scroll to the end (as MainWindow does on every ItemsRepeater layout
15- // update) and does so, which is what will trigger the ScrollChanged below.
16- Assert . True ( tracker . ShouldScrollToEnd ( ) ) ;
17-
18- // Before that resulting ScrollChanged is processed, more lines already grew the extent
19- // further (104 -> 130) while the offset still reflects the smaller extent it was set
20- // against (54). The user never touched the scrollbar, so auto-scroll should not detach.
13+ // Simulates a burst of fast-arriving log lines: ScrollToEnd() was called while the
14+ // extent was still 104 (viewport 50), setting the offset to 54. Before that resulting
15+ // ScrollChanged is processed, more lines already grew the extent further to 130. The
16+ // offset only ever moved forward, so this is not the user scrolling away.
2117 tracker . OnScrollChanged ( offsetY : 54 , extentHeight : 130 , viewportHeight : 50 ) ;
2218
2319 Assert . True ( tracker . AutoScroll ) ;
2420 }
2521
2622 [ Fact ]
27- public void OnScrollChanged_UserScrollsAwayWithoutScrollToEnd_Detaches ( )
23+ public void OnScrollChanged_UserDragsScrollbarUp_Detaches ( )
2824 {
2925 var tracker = new AutoScrollTracker ( ) ;
26+ tracker . OnScrollChanged ( offsetY : 76 , extentHeight : 130 , viewportHeight : 50 ) ; // starts at bottom
3027
31- // No ShouldScrollToEnd() call precedes this - the user dragged the scrollbar up themselves.
32- tracker . OnScrollChanged ( offsetY : 0 , extentHeight : 130 , viewportHeight : 50 ) ;
28+ // The offset moves backward - only a manual scrollbar drag does that.
29+ tracker . OnScrollChanged ( offsetY : 20 , extentHeight : 130 , viewportHeight : 50 ) ;
30+
31+ Assert . False ( tracker . AutoScroll ) ;
32+ }
33+
34+ [ Fact ]
35+ public void OnScrollChanged_UserDragsAwayAfterSustainedAutoScrolling_StillDetaches ( )
36+ {
37+ var tracker = new AutoScrollTracker ( ) ;
38+
39+ // Content keeps growing, offset keeps chasing it forward - auto-scroll stays engaged.
40+ tracker . OnScrollChanged ( offsetY : 50 , extentHeight : 104 , viewportHeight : 50 ) ;
41+ tracker . OnScrollChanged ( offsetY : 76 , extentHeight : 130 , viewportHeight : 50 ) ;
42+ Assert . True ( tracker . AutoScroll ) ;
43+
44+ // The user then grabs the scrollbar and drags it up.
45+ tracker . OnScrollChanged ( offsetY : 20 , extentHeight : 130 , viewportHeight : 50 ) ;
3346
3447 Assert . False ( tracker . AutoScroll ) ;
3548 }
0 commit comments