* Binary search to find the index of the first item at or after the given scroll position
(scrollTop: number)
| 228 | * Binary search to find the index of the first item at or after the given scroll position |
| 229 | */ |
| 230 | private binarySearchPosition(scrollTop: number): number { |
| 231 | if (this.positionCache.length === 0) return 0; |
| 232 | |
| 233 | let left = 0; |
| 234 | let right = this.positionCache.length - 1; |
| 235 | |
| 236 | while (left < right) { |
| 237 | const mid = Math.floor((left + right) / 2); |
| 238 | if (this.positionCache[mid] < scrollTop) { |
| 239 | left = mid + 1; |
| 240 | } else { |
| 241 | right = mid; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | return Math.max(0, left - 1); |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Get the height of an item (measured or estimated) |