( scrollTop: number, viewport: number, totalLines: number, overscan = OVERSCAN_LINES )
| 127 | |
| 128 | /** The 1-based lines to render for a scroll position, with overscan. */ |
| 129 | export 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 |
no outgoing calls
no test coverage detected