@@ -702,14 +702,20 @@ export class Virtualizer<
702
702
)
703
703
704
704
calculateRange = memo (
705
- ( ) => [ this . getMeasurements ( ) , this . getSize ( ) , this . getScrollOffset ( ) ] ,
706
- ( measurements , outerSize , scrollOffset ) => {
705
+ ( ) => [
706
+ this . getMeasurements ( ) ,
707
+ this . getSize ( ) ,
708
+ this . getScrollOffset ( ) ,
709
+ this . options . lanes ,
710
+ ] ,
711
+ ( measurements , outerSize , scrollOffset , lanes ) => {
707
712
return ( this . range =
708
713
measurements . length > 0 && outerSize > 0
709
714
? calculateRange ( {
710
715
measurements,
711
716
outerSize,
712
717
scrollOffset,
718
+ lanes,
713
719
} )
714
720
: null )
715
721
} ,
@@ -1105,23 +1111,37 @@ function calculateRange({
1105
1111
measurements,
1106
1112
outerSize,
1107
1113
scrollOffset,
1114
+ lanes,
1108
1115
} : {
1109
1116
measurements : Array < VirtualItem >
1110
1117
outerSize : number
1111
1118
scrollOffset : number
1119
+ lanes : number
1112
1120
} ) {
1113
- const count = measurements . length - 1
1121
+ const lastIndex = measurements . length - 1
1114
1122
const getOffset = ( index : number ) => measurements [ index ] ! . start
1115
1123
1116
- const startIndex = findNearestBinarySearch ( 0 , count , getOffset , scrollOffset )
1124
+ let startIndex = findNearestBinarySearch (
1125
+ 0 ,
1126
+ lastIndex ,
1127
+ getOffset ,
1128
+ scrollOffset ,
1129
+ )
1117
1130
let endIndex = startIndex
1118
1131
1119
1132
while (
1120
- endIndex < count &&
1133
+ endIndex < lastIndex &&
1121
1134
measurements [ endIndex ] ! . end < scrollOffset + outerSize
1122
1135
) {
1123
1136
endIndex ++
1124
1137
}
1125
1138
1139
+ if ( lanes > 1 ) {
1140
+ // Align startIndex to the beginning of its lane
1141
+ startIndex = Math . max ( 0 , startIndex - ( startIndex % lanes ) )
1142
+ // Align endIndex to the end of its lane
1143
+ endIndex = Math . min ( lastIndex , endIndex + ( lanes - 1 - ( endIndex % lanes ) ) )
1144
+ }
1145
+
1126
1146
return { startIndex, endIndex }
1127
1147
}
0 commit comments