diff --git a/src/components/FileTree.tsx b/src/components/FileTree.tsx index 1684a61..3d30c5c 100644 --- a/src/components/FileTree.tsx +++ b/src/components/FileTree.tsx @@ -85,13 +85,15 @@ export const HeadingNode: Component<{ const href = `${props.basePath}#${anchor}`; const hasChildren = !!props.node.children; // 默认收起,除非当前锚点在该节点内 - const [isExpanded, setIsExpanded] = createSignal(false); + const [isExpanded, setIsExpanded] = createSignal(props.depth <= 0); - const handleClick = (e: MouseEvent) => { + const handleExpand = (e: MouseEvent) => { e.preventDefault(); if (hasChildren) { setIsExpanded(!isExpanded()); } + }; + const handleClick = (e: MouseEvent) => { navigate(href); // 滚动到目标元素,考虑导航栏高度偏移 requestAnimationFrame(() => { @@ -100,7 +102,7 @@ export const HeadingNode: Component<{ const navBarHeight = 80; const elementPosition = element.getBoundingClientRect().top; const offsetPosition = window.scrollY + elementPosition - navBarHeight; - window.scrollTo({ top: offsetPosition, behavior: "smooth" }); + window.scrollTo({ top: offsetPosition, behavior: "instant" }); } }); }; @@ -109,17 +111,17 @@ export const HeadingNode: Component<{ return (
+ + ▶ + - - - {isExpanded() ? "▼" : "▶"} - - {props.node.title}