From 30a4dce0a73966ca9ff67a35f412206d92c36694 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Sat, 7 Mar 2026 21:56:20 +0800 Subject: [PATCH 1/2] feat: code file tree switch file to active node --- app/components/Code/FileTree.vue | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/components/Code/FileTree.vue b/app/components/Code/FileTree.vue index 1bcf251485..3f0d562a35 100644 --- a/app/components/Code/FileTree.vue +++ b/app/components/Code/FileTree.vue @@ -36,12 +36,20 @@ function getFileRoute(nodePath: string): RouteLocationRaw { const { toggleDir, isExpanded, autoExpandAncestors } = useFileTreeState(props.baseUrl) +const scrollIntoView = () => { + const el = document.querySelector('[aria-current="true"]') as HTMLElement + if (el) { + el.scrollIntoView({ block: 'center' }) + } +} + // Auto-expand directories in the current path watch( () => props.currentPath, path => { if (path) { autoExpandAncestors(path) + nextTick(scrollIntoView) } }, { immediate: true }, From ab143725312b83037ccdd7702a2b2e67664c7bdc Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Sat, 7 Mar 2026 22:08:30 +0800 Subject: [PATCH 2/2] fix: apply review --- app/components/Code/FileTree.vue | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/components/Code/FileTree.vue b/app/components/Code/FileTree.vue index 3f0d562a35..b4410537dc 100644 --- a/app/components/Code/FileTree.vue +++ b/app/components/Code/FileTree.vue @@ -13,6 +13,7 @@ const props = defineProps<{ }>() const depth = computed(() => props.depth ?? 0) +const treeRoot = useTemplateRef('treeRoot') // Check if a node or any of its children is currently selected function isNodeActive(node: PackageFileTree): boolean { @@ -37,7 +38,7 @@ function getFileRoute(nodePath: string): RouteLocationRaw { const { toggleDir, isExpanded, autoExpandAncestors } = useFileTreeState(props.baseUrl) const scrollIntoView = () => { - const el = document.querySelector('[aria-current="true"]') as HTMLElement + const el = treeRoot.value?.querySelector('[aria-current="true"]') as HTMLElement if (el) { el.scrollIntoView({ block: 'center' }) } @@ -57,7 +58,7 @@ watch(