@@ -120,6 +120,7 @@ const viewRows = computed(() =>
120120const bufferRows = computed (() => Math .max (1 , Math .floor (viewRows .value / 3 )))
121121const windowSize = computed (() => viewRows .value + bufferRows .value * 2 )
122122
123+ // Compute window ranges for all nodes
123124const parentWindowRanges = computed <Record <string , WindowRange >>(() => {
124125 if (! containerHeight .value || ! renderedRoot .value .children ) {
125126 return {}
@@ -130,7 +131,6 @@ const parentWindowRanges = computed<Record<string, WindowRange>>(() => {
130131 const scrollBottom = scrollTop + containerHeight .value
131132
132133 const nodePositions = new Map <string , number >()
133- const nodeEndPositions = new Map <string , number >()
134134 let currentPos = 0
135135
136136 const calculatePositions = (node : RenderedTreeExplorerNode ): number => {
@@ -144,37 +144,39 @@ const parentWindowRanges = computed<Record<string, WindowRange>>(() => {
144144 }
145145 }
146146
147- nodeEndPositions .set (node .key , currentPos )
148147 return currentPos
149148 }
150149
151150 for (const child of renderedRoot .value .children ) {
152151 currentPos = calculatePositions (child )
153152 }
154153
155- const computeNodeWindow = (node : RenderedTreeExplorerNode ) => {
154+ const computeNodeWindow = (node : RenderedTreeExplorerNode ): void => {
156155 if (! node .children || node .leaf ) return
157156
158157 const isExpanded = expandedKeys .value ?.[node .key ] ?? false
159158 if (! isExpanded ) return
160159
161- const nodeStart = nodePositions .get (node .key ) ?? 0
162- const childrenStart = nodeStart + DEFAULT_NODE_HEIGHT
163160 const totalChildren = node .children .length
164-
165161 if (totalChildren === 0 ) return
166162
167- const childrenEnd = nodeEndPositions .get (node .key ) ?? childrenStart
163+ for (const child of node .children ) {
164+ computeNodeWindow (child )
165+ }
168166
169- const relativeScrollTop = Math .max (0 , scrollTop - childrenStart )
170- const relativeScrollBottom = Math .max (0 , scrollBottom - childrenStart )
167+ const nodeStart = nodePositions .get (node .key ) ?? 0
168+ const childrenStart = nodeStart + DEFAULT_NODE_HEIGHT
169+ const estimatedChildrenEnd = childrenStart + totalChildren * DEFAULT_NODE_HEIGHT
171170
172171 const bufferHeight = bufferRows .value * DEFAULT_NODE_HEIGHT
173- const childrenAreaVisible =
174- childrenStart <= scrollBottom + bufferHeight &&
175- childrenEnd >= scrollTop - bufferHeight
172+ const isInView =
173+ estimatedChildrenEnd >= scrollTop - bufferHeight &&
174+ childrenStart <= scrollBottom + bufferHeight
175+
176+ if (isInView ) {
177+ const relativeScrollTop = Math .max (0 , scrollTop - childrenStart )
178+ const relativeScrollBottom = Math .max (0 , scrollBottom - childrenStart )
176179
177- if (childrenAreaVisible ) {
178180 const fromRow = Math .max (
179181 0 ,
180182 Math .floor (relativeScrollTop / DEFAULT_NODE_HEIGHT ) - bufferRows .value
@@ -192,16 +194,11 @@ const parentWindowRanges = computed<Record<string, WindowRange>>(() => {
192194 )
193195 }
194196 } else {
195- // Node is outside visible range, show initial window
196197 ranges [node .key ] = createInitialWindowRange (
197198 totalChildren ,
198199 windowSize .value
199200 )
200201 }
201-
202- for (const child of node .children ) {
203- computeNodeWindow (child )
204- }
205202 }
206203
207204 for (const child of renderedRoot .value .children ) {
0 commit comments