@@ -2,12 +2,14 @@ import { useMemo } from "react";
22import type { DiffFile , LayoutMode } from "../../core/types" ;
33import { AgentInlineNote , AgentInlineNoteGuideCap } from "../components/panes/AgentInlineNote" ;
44import type { VisibleAgentNote } from "../lib/agentAnnotations" ;
5+ import type { DiffSectionGeometry } from "../lib/diffSectionGeometry" ;
56import { reviewRowId } from "../lib/ids" ;
67import type { AppTheme } from "../themes" ;
78import { findMaxLineNumber } from "./codeColumns" ;
89import { buildSplitRows , buildStackRows } from "./pierre" ;
910import { plannedReviewRowVisible } from "./plannedReviewRows" ;
1011import { buildReviewRenderPlan } from "./reviewRenderPlan" ;
12+ import { resolveVisiblePlannedRowWindow , type VisibleBodyBounds } from "./rowWindowing" ;
1113import { diffMessage , DiffRowView , fitText } from "./renderRows" ;
1214import { useHighlightedDiff } from "./useHighlightedDiff" ;
1315
@@ -28,8 +30,10 @@ export function PierreDiffView({
2830 visibleAgentNotes = EMPTY_VISIBLE_AGENT_NOTES ,
2931 width,
3032 selectedHunkIndex,
33+ sectionGeometry,
3134 shouldLoadHighlight = true ,
3235 scrollable = true ,
36+ visibleBodyBounds,
3337} : {
3438 annotatedHunkIndices ?: Set < number > ;
3539 codeHorizontalOffset ?: number ;
@@ -43,8 +47,10 @@ export function PierreDiffView({
4347 visibleAgentNotes ?: VisibleAgentNote [ ] ;
4448 width : number ;
4549 selectedHunkIndex : number ;
50+ sectionGeometry ?: DiffSectionGeometry ;
4651 shouldLoadHighlight ?: boolean ;
4752 scrollable ?: boolean ;
53+ visibleBodyBounds ?: VisibleBodyBounds ;
4854} ) {
4955 const resolvedHighlighted = useHighlightedDiff ( {
5056 file,
@@ -74,6 +80,35 @@ export function PierreDiffView({
7480 [ file , rows , showHunkHeaders , visibleAgentNotes ] ,
7581 ) ;
7682 const lineNumberDigits = useMemo ( ( ) => String ( file ? findMaxLineNumber ( file ) : 1 ) . length , [ file ] ) ;
83+ const visiblePlannedRowWindow = useMemo ( ( ) => {
84+ // Fall back to the full row list unless all three row-windowing inputs are ready:
85+ // - the complete planned row stream for this file
86+ // - measured per-row geometry for that same stream
87+ // - one file-local visible body slice from DiffPane
88+ // The helper relies on those structures staying in lockstep, so any missing input means
89+ // "render everything" instead of risking a mismatched partial slice.
90+ if ( ! sectionGeometry || ! visibleBodyBounds ) {
91+ return {
92+ bottomSpacerHeight : 0 ,
93+ plannedRows,
94+ topSpacerHeight : 0 ,
95+ } ;
96+ }
97+
98+ // `visibleBodyBounds` is already relative to this file body, not the whole review stream.
99+ // Example: if DiffPane says "mount rows 120..260 within package-lock.json", this helper keeps
100+ // only the planned rows whose measured bounds overlap that interval.
101+ //
102+ // The return value is not just the sliced rows. It also includes spacer heights for the skipped
103+ // region above and below so the file still occupies its original total body height inside the
104+ // scroll stream. That lets navigation, sticky headers, and reveal math keep using the same
105+ // absolute geometry even though most rows are temporarily unmounted.
106+ return resolveVisiblePlannedRowWindow ( {
107+ plannedRows,
108+ sectionGeometry,
109+ visibleBodyBounds,
110+ } ) ;
111+ } , [ plannedRows , sectionGeometry , visibleBodyBounds ] ) ;
77112
78113 if ( ! file ) {
79114 return (
@@ -93,7 +128,18 @@ export function PierreDiffView({
93128
94129 const content = (
95130 < box style = { { width : "100%" , flexDirection : "column" } } >
96- { plannedRows . map ( ( plannedRow ) => {
131+ { visiblePlannedRowWindow . topSpacerHeight > 0 ? (
132+ // Reserve the skipped height above the mounted slice so the file body keeps its original
133+ // absolute row positions inside the larger review stream.
134+ < box
135+ style = { {
136+ width : "100%" ,
137+ height : visiblePlannedRowWindow . topSpacerHeight ,
138+ backgroundColor : theme . panel ,
139+ } }
140+ />
141+ ) : null }
142+ { visiblePlannedRowWindow . plannedRows . map ( ( plannedRow ) => {
97143 // Mirror the same visibility/id decisions used by the scroll-bound helpers so the mounted
98144 // tree can be measured by hunk later.
99145 const rowId = reviewRowId ( plannedRow . key ) ;
@@ -154,6 +200,16 @@ export function PierreDiffView({
154200 </ box >
155201 ) ;
156202 } ) }
203+ { visiblePlannedRowWindow . bottomSpacerHeight > 0 ? (
204+ // Mirror that reservation below the mounted slice so total file-body height stays stable.
205+ < box
206+ style = { {
207+ width : "100%" ,
208+ height : visiblePlannedRowWindow . bottomSpacerHeight ,
209+ backgroundColor : theme . panel ,
210+ } }
211+ />
212+ ) : null }
157213 </ box >
158214 ) ;
159215
0 commit comments