From e094e42c07d07ec6cc06a40cf646d3e1ae587e3b Mon Sep 17 00:00:00 2001 From: Yourz Date: Mon, 15 Dec 2025 20:20:14 +0800 Subject: [PATCH] refactor: apply coderabbitai suggestions - Use createInitialWindowRange and calculateSpacerHeights in getTotalSpacerHeights - Use active range after shift for recursive window processing - Remove unused export from findNodeByKey --- src/components/common/TreeExplorer.vue | 25 +++++++++++++++++-------- src/utils/treeUtil.ts | 5 +---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/components/common/TreeExplorer.vue b/src/components/common/TreeExplorer.vue index ecd24753d..75d281f0a 100644 --- a/src/components/common/TreeExplorer.vue +++ b/src/components/common/TreeExplorer.vue @@ -140,13 +140,17 @@ const getTotalSpacerHeights = () => { if (!isExpanded) return const totalChildren = node.children.length - const range = parentWindowRanges.value[node.key] ?? { - start: 0, - end: Math.min(WINDOW_SIZE, totalChildren) - } + const range = + parentWindowRanges.value[node.key] ?? + createInitialWindowRange(totalChildren, WINDOW_SIZE) - topTotal += range.start * NODE_HEIGHT - bottomTotal += (totalChildren - range.end) * NODE_HEIGHT + const { topSpacer, bottomSpacer } = calculateSpacerHeights( + totalChildren, + range, + NODE_HEIGHT + ) + topTotal += topSpacer + bottomTotal += bottomSpacer // Recursively check children in the window for (let i = range.start; i < range.end && i < node.children.length; i++) { @@ -244,8 +248,13 @@ const shiftNodeWindow = ( parentWindowRanges.value[node.key] = newRange } - // Recursively process children in current window - for (let i = range.start; i < range.end && i < node.children.length; i++) { + // Recursively process children in the active window (after shift) + const activeRange = newRange ?? range + for ( + let i = activeRange.start; + i < activeRange.end && i < node.children.length; + i++ + ) { shiftNodeWindow(node.children[i], direction) } } diff --git a/src/utils/treeUtil.ts b/src/utils/treeUtil.ts index 21f1e45d6..74d27c32d 100644 --- a/src/utils/treeUtil.ts +++ b/src/utils/treeUtil.ts @@ -105,10 +105,7 @@ export function sortedTree( return newNode } -export const findNodeByKey = ( - root: T, - key: string -): T | null => { +const findNodeByKey = (root: T, key: string): T | null => { if (root.key === key) { return root }