Prerequisites
Describe the feature
The Virtualizer class already tracks scrollTop, scrollHeight, and has getOffsetInScrollContainer(element) — it knows its own layout. But there's no API for scrolling to a specific line number programmatically.
Current workaround: Consumers must implement a two-phase scroll:
- Compute an approximate scroll position using
(lineNumber / totalLines) * scrollHeight
- Scroll instantly to that position (triggering the virtualizer to render that area)
- Poll/wait for the target
[data-line="N"] element to appear in the shadow DOM
- Call
scrollIntoView() on the found element
This is fragile because the proportion-based approximation doesn't account for injected content (annotations, hunk separators, file headers) that adds uneven height. With many annotations above the target line, the approximation can be off by hundreds of pixels — sometimes enough that the virtualizer doesn't render the target area at all.
Proposed API
// On the Virtualizer class:
scrollToLine(lineNumber: number, options?: { behavior?: ScrollBehavior; block?: ScrollLogicalPosition }): void
Since the Virtualizer manages the scroll container and knows the actual rendered heights of all content, it can compute the exact scroll offset for any line — no approximation needed.
Alternatives considered
- Proportion-based scroll + polling (current approach): works ~80% of the time, fails when annotation panels add significant height before the target
- Using
getOffsetInScrollContainer(element): requires the element to already exist in the DOM, which it doesn't for virtualized off-screen lines
What version of @pierre/diffs are you using?
1.1.7
Prerequisites
Describe the feature
The
Virtualizerclass already tracksscrollTop,scrollHeight, and hasgetOffsetInScrollContainer(element)— it knows its own layout. But there's no API for scrolling to a specific line number programmatically.Current workaround: Consumers must implement a two-phase scroll:
(lineNumber / totalLines) * scrollHeight[data-line="N"]element to appear in the shadow DOMscrollIntoView()on the found elementThis is fragile because the proportion-based approximation doesn't account for injected content (annotations, hunk separators, file headers) that adds uneven height. With many annotations above the target line, the approximation can be off by hundreds of pixels — sometimes enough that the virtualizer doesn't render the target area at all.
Proposed API
Since the
Virtualizermanages the scroll container and knows the actual rendered heights of all content, it can compute the exact scroll offset for any line — no approximation needed.Alternatives considered
getOffsetInScrollContainer(element): requires the element to already exist in the DOM, which it doesn't for virtualized off-screen linesWhat version of @pierre/diffs are you using?
1.1.7