MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / getVirtualRange

Function getVirtualRange

packages/app-core/src/lib/virtual-list.ts:15–40  ·  view source on GitHub ↗
({
  itemCount,
  itemSize,
  scrollTop,
  viewportHeight,
  overscan = 6
}: VirtualRangeInput)

Source from the content-addressed store, hash-verified

13}
14
15export function getVirtualRange({
16 itemCount,
17 itemSize,
18 scrollTop,
19 viewportHeight,
20 overscan = 6
21}: VirtualRangeInput): VirtualRange {
22 const count = Math.max(0, Math.floor(itemCount))
23 if (count === 0) return { start: 0, end: 0, totalSize: 0 }
24
25 const size = Math.max(1, itemSize)
26 const safeScrollTop = Math.max(0, scrollTop)
27 const safeOverscan = Math.max(0, Math.floor(overscan))
28 const visibleStart = Math.min(count - 1, Math.floor(safeScrollTop / size))
29 const visibleCount =
30 viewportHeight > 0 ? Math.max(1, Math.ceil(viewportHeight / size)) : safeOverscan + 1
31
32 const start = Math.max(0, visibleStart - safeOverscan)
33 const end = Math.min(count, visibleStart + visibleCount + safeOverscan)
34
35 return {
36 start,
37 end,
38 totalSize: count * size
39 }
40}
41
42export interface VirtualIndexScrollInput {
43 index: number

Callers 4

NoteListFunction · 0.90
WindowedLeafEntriesFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected