@@ -174,12 +174,13 @@ public override void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutR
174174 // Reserve arrow positions so thumb never overlaps them
175175 int arrowSlots = effectiveViewport >= 3 ? 2 : 0 ;
176176 int thumbTrackHeight = effectiveViewport - arrowSlots ;
177- vThumbHeight = Math . Max ( 1 , ( int ) ( thumbTrackHeight * ( ( double ) effectiveViewport / Math . Max ( 1 , totalWrappedLineCount ) ) ) ) ;
177+ vThumbHeight = Math . Clamp ( ( int ) ( thumbTrackHeight * ( ( double ) effectiveViewport / Math . Max ( 1 , totalWrappedLineCount ) ) ) , 1 , thumbTrackHeight ) ;
178178 vThumbPos = arrowSlots > 0 ? 1 : 0 ; // start after top arrow
179179 if ( totalWrappedLineCount > effectiveViewport )
180180 {
181+ int maxThumbPos = thumbTrackHeight - vThumbHeight ;
181182 double scrollRatio = ( double ) _verticalScrollOffset / ( totalWrappedLineCount - effectiveViewport ) ;
182- vThumbPos += ( int ) Math . Round ( ( thumbTrackHeight - vThumbHeight ) * scrollRatio ) ;
183+ vThumbPos += Math . Min ( ( int ) Math . Round ( maxThumbPos * scrollRatio ) , maxThumbPos ) ;
183184 }
184185 }
185186
@@ -509,12 +510,12 @@ public override void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutR
509510 // Reserve arrow positions so thumb never overlaps them
510511 int hArrowSlots = effectiveWidth >= 3 ? 2 : 0 ;
511512 int hThumbTrackWidth = effectiveWidth - hArrowSlots ;
512- int thumbWidth = Math . Max ( 1 , ( hThumbTrackWidth * hThumbTrackWidth ) / Math . Max ( 1 , maxLineLength ) ) ;
513+ int thumbWidth = Math . Clamp ( ( hThumbTrackWidth * hThumbTrackWidth ) / Math . Max ( 1 , maxLineLength ) , 1 , hThumbTrackWidth ) ;
513514 int thumbPos = hArrowSlots > 0 ? 1 : 0 ;
514515 if ( maxLineLength > effectiveWidth )
515516 {
516517 int maxThumbPos = hThumbTrackWidth - thumbWidth ;
517- thumbPos += ( int ) Math . Round ( ( double ) _horizontalScrollOffset / ( maxLineLength - effectiveWidth ) * maxThumbPos ) ;
518+ thumbPos += Math . Min ( ( int ) Math . Round ( ( double ) _horizontalScrollOffset / ( maxLineLength - effectiveWidth ) * maxThumbPos ) , maxThumbPos ) ;
518519 }
519520
520521 for ( int x = 0 ; x < effectiveWidth ; x ++ )
@@ -616,12 +617,12 @@ private int GetGutterWidth()
616617 // Reserve arrow positions so thumb never overlaps them
617618 int arrowSlots = effectiveViewport >= 3 ? 2 : 0 ;
618619 int thumbTrackHeight = effectiveViewport - arrowSlots ;
619- int thumbHeight = Math . Max ( 1 , ( thumbTrackHeight * thumbTrackHeight ) / Math . Max ( 1 , totalLines ) ) ;
620+ int thumbHeight = Math . Clamp ( ( int ) ( thumbTrackHeight * ( ( double ) effectiveViewport / Math . Max ( 1 , totalLines ) ) ) , 1 , thumbTrackHeight ) ;
620621 int thumbY = arrowSlots > 0 ? 1 : 0 ;
621622 if ( totalLines > effectiveViewport )
622623 {
623624 int maxThumbPos = thumbTrackHeight - thumbHeight ;
624- thumbY += ( int ) Math . Round ( ( double ) _verticalScrollOffset / ( totalLines - effectiveViewport ) * maxThumbPos ) ;
625+ thumbY += Math . Min ( ( int ) Math . Round ( ( double ) _verticalScrollOffset / ( totalLines - effectiveViewport ) * maxThumbPos ) , maxThumbPos ) ;
625626 }
626627 return ( effectiveViewport , thumbY , thumbHeight ) ;
627628 }
@@ -636,12 +637,12 @@ private int GetGutterWidth()
636637 // Reserve arrow positions so thumb never overlaps them
637638 int arrowSlots = _effectiveWidth >= 3 ? 2 : 0 ;
638639 int thumbTrackWidth = _effectiveWidth - arrowSlots ;
639- int thumbWidth = Math . Max ( 1 , ( thumbTrackWidth * thumbTrackWidth ) / Math . Max ( 1 , maxLineLength ) ) ;
640+ int thumbWidth = Math . Clamp ( ( thumbTrackWidth * thumbTrackWidth ) / Math . Max ( 1 , maxLineLength ) , 1 , thumbTrackWidth ) ;
640641 int thumbX = arrowSlots > 0 ? 1 : 0 ;
641642 if ( maxLineLength > _effectiveWidth )
642643 {
643644 int maxThumbPos = thumbTrackWidth - thumbWidth ;
644- thumbX += ( int ) Math . Round ( ( double ) _horizontalScrollOffset / ( maxLineLength - _effectiveWidth ) * maxThumbPos ) ;
645+ thumbX += Math . Min ( ( int ) Math . Round ( ( double ) _horizontalScrollOffset / ( maxLineLength - _effectiveWidth ) * maxThumbPos ) , maxThumbPos ) ;
645646 }
646647 return ( _effectiveWidth , thumbX , thumbWidth ) ;
647648 }
0 commit comments