2424 e.stopImmediatePropagation()
2525 }
2626 }),
27- nodeChildren: ({ instance }) => getNodeChildrenStyle(instance)
27+ nodeChildren: ({ instance }) => getNodeChildrenStyle(instance.node as RenderedTreeExplorerNode )
2828 }"
2929 >
3030 <template #folder =" { node } " >
@@ -120,8 +120,6 @@ 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 based on scroll position
124- // Each node's window is calculated relative to its children list
125123const parentWindowRanges = computed <Record <string , WindowRange >>(() => {
126124 if (! containerHeight .value || ! renderedRoot .value .children ) {
127125 return {}
@@ -131,8 +129,8 @@ const parentWindowRanges = computed<Record<string, WindowRange>>(() => {
131129 const scrollTop = scrollY .value
132130 const scrollBottom = scrollTop + containerHeight .value
133131
134- // Calculate cumulative positions for nodes in the tree
135132 const nodePositions = new Map <string , number >()
133+ const nodeEndPositions = new Map <string , number >()
136134 let currentPos = 0
137135
138136 const calculatePositions = (node : RenderedTreeExplorerNode ): number => {
@@ -146,14 +144,14 @@ const parentWindowRanges = computed<Record<string, WindowRange>>(() => {
146144 }
147145 }
148146
147+ nodeEndPositions .set (node .key , currentPos )
149148 return currentPos
150149 }
151150
152151 for (const child of renderedRoot .value .children ) {
153152 currentPos = calculatePositions (child )
154153 }
155154
156- // Compute windows for each node based on scroll position
157155 const computeNodeWindow = (node : RenderedTreeExplorerNode ) => {
158156 if (! node .children || node .leaf ) return
159157
@@ -162,21 +160,21 @@ const parentWindowRanges = computed<Record<string, WindowRange>>(() => {
162160
163161 const nodeStart = nodePositions .get (node .key ) ?? 0
164162 const childrenStart = nodeStart + DEFAULT_NODE_HEIGHT
165- const childrenEnd =
166- childrenStart + node .children .length * DEFAULT_NODE_HEIGHT
163+ const totalChildren = node .children .length
167164
168- // Check if this node's children are in the visible range
169- const isVisible =
170- childrenEnd >= scrollTop - bufferRows .value * DEFAULT_NODE_HEIGHT &&
171- childrenStart <= scrollBottom + bufferRows .value * DEFAULT_NODE_HEIGHT
165+ if (totalChildren === 0 ) return
172166
173- const totalChildren = node .children .length
167+ const childrenEnd = nodeEndPositions .get (node .key ) ?? childrenStart
168+
169+ const relativeScrollTop = Math .max (0 , scrollTop - childrenStart )
170+ const relativeScrollBottom = Math .max (0 , scrollBottom - childrenStart )
174171
175- if ( isVisible && totalChildren > 0 ) {
176- // Calculate which children should be visible based on scroll position
177- const relativeScrollTop = Math . max ( 0 , scrollTop - childrenStart )
178- const relativeScrollBottom = Math . max ( 0 , scrollBottom - childrenStart )
172+ const bufferHeight = bufferRows . value * DEFAULT_NODE_HEIGHT
173+ const childrenAreaVisible =
174+ childrenStart <= scrollBottom + bufferHeight &&
175+ childrenEnd >= scrollTop - bufferHeight
179176
177+ if (childrenAreaVisible ) {
180178 const fromRow = Math .max (
181179 0 ,
182180 Math .floor (relativeScrollTop / DEFAULT_NODE_HEIGHT ) - bufferRows .value
@@ -194,17 +192,15 @@ const parentWindowRanges = computed<Record<string, WindowRange>>(() => {
194192 )
195193 }
196194 } else {
197- // Node is outside visible range, use minimal window
195+ // Node is outside visible range, show initial window
198196 ranges [node .key ] = createInitialWindowRange (
199197 totalChildren ,
200198 windowSize .value
201199 )
202200 }
203201
204- // Recursively compute windows for children
205- const range = ranges [node .key ]
206- for (let i = range .start ; i < range .end && i < node .children .length ; i ++ ) {
207- computeNodeWindow (node .children [i ])
202+ for (const child of node .children ) {
203+ computeNodeWindow (child )
208204 }
209205 }
210206
@@ -271,8 +267,7 @@ const displayRoot = computed<RenderedTreeExplorerNode>(() => ({
271267 )
272268}))
273269
274- const getNodeChildrenStyle = (instance : any ) => {
275- const node = instance .node as RenderedTreeExplorerNode
270+ const getNodeChildrenStyle = (node : RenderedTreeExplorerNode ) => {
276271 if (! node ?.children || node .leaf ) {
277272 return { class: ' virtual-node-children' }
278273 }
0 commit comments