Skip to content

Commit ca43400

Browse files
committed
fix: improve tree scrolling behavior in WindowCard component
1 parent 037a424 commit ca43400

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/views/snapshot/WindowCard.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const rootNode = snapshotStore.rootNode as ShallowRef<RawNode>;
2424
let lastClickId = Number.NaN;
2525
const expandedKeys = shallowRef<number[]>([]);
2626
const selectedKeys = shallowRef<number[]>([]);
27+
const treeContainer = useTemplateRef('treeContainerRef');
2728
watch([() => focusNode.value, () => focusTime.value], async () => {
2829
if (!focusNode.value) return;
2930
const key = focusNode.value.id;
@@ -36,7 +37,19 @@ watch([() => focusNode.value, () => focusTime.value], async () => {
3637
return;
3738
}
3839
selectedKeys.value = [key];
39-
treeRef.value?.scrollTo({ key, behavior: 'smooth', debounce: true });
40+
if (!treeContainer.value) return;
41+
const nodeRef = treeContainer.value.querySelector(
42+
`[data-node-id="${key}"]`,
43+
);
44+
if (nodeRef) {
45+
nodeRef.scrollIntoView({
46+
behavior: 'smooth',
47+
block: 'center',
48+
});
49+
} else {
50+
await delay(300);
51+
treeRef.value?.scrollTo({ key, behavior: 'smooth', debounce: true });
52+
}
4053
}
4154
});
4255
let parent = focusNode.value.parent;
@@ -214,7 +227,7 @@ const gkdVersionName = computed(() => {
214227
/>
215228
</div>
216229
<div h-1px mt-4px bg="#efeff5" />
217-
<div flex-1 min-h-0>
230+
<div ref="treeContainerRef" flex-1 min-h-0>
218231
<NTree
219232
ref="treeRef"
220233
v-model:expandedKeys="expandedKeys"

0 commit comments

Comments
 (0)