fix: misc
This commit is contained in:
@@ -2,6 +2,15 @@ import { Component, createMemo, createSignal, Show } from "solid-js";
|
||||
import { type FileNode, type TocNode } from "../data-loader";
|
||||
import { useNavigate } from "@solidjs/router";
|
||||
|
||||
/**
|
||||
* 检查当前文件路径是否在文件夹内
|
||||
*/
|
||||
function isPathInDir(currentPath: string, dirPath: string): boolean {
|
||||
// 确保 dirPath 以 / 结尾,用于前缀匹配
|
||||
const dirPathPrefix = dirPath.endsWith('/') ? dirPath : dirPath + '/';
|
||||
return currentPath.startsWith(dirPathPrefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件树节点组件
|
||||
*/
|
||||
@@ -13,9 +22,10 @@ export const FileTreeNode: Component<{
|
||||
onClose: () => void;
|
||||
}> = (props) => {
|
||||
const navigate = useNavigate();
|
||||
const [isExpanded, setIsExpanded] = createSignal(true);
|
||||
const isDir = !!props.node.children;
|
||||
const isActive = createMemo(() => props.currentPath === props.node.path);
|
||||
// 默认收起,除非当前文件在该文件夹内
|
||||
const [isExpanded, setIsExpanded] = createSignal(isDir && isPathInDir(props.currentPath, props.node.path));
|
||||
|
||||
const handleClick = () => {
|
||||
if (isDir) {
|
||||
|
||||
Reference in New Issue
Block a user