MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / visibleLines

Function visibleLines

ui/src/lib/filecode-model.ts:129–140  ·  view source on GitHub ↗
(
  scrollTop: number,
  viewport: number,
  totalLines: number,
  overscan = OVERSCAN_LINES
)

Source from the content-addressed store, hash-verified

127
128/** The 1-based lines to render for a scroll position, with overscan. */
129export function visibleLines(
130 scrollTop: number,
131 viewport: number,
132 totalLines: number,
133 overscan = OVERSCAN_LINES
134): { first: number; last: number } {
135 if (totalLines <= 0) return { first: 1, last: 0 };
136 const firstRaw = Math.floor((scrollTop - CODE_TOP_PAD) / CODE_LINE_HEIGHT) + 1 - overscan;
137 const count = Math.ceil((viewport || 800) / CODE_LINE_HEIGHT) + overscan * 2;
138 const first = Math.max(1, Math.min(totalLines, firstRaw));
139 return { first, last: Math.max(first - 1, Math.min(totalLines, first + count)) };
140}
141
142/* ---------------------------------------------------------------- pages -- */
143

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected