diff --git a/src/lib/components/editor/(filesystem)/index.ts b/src/lib/components/editor/(filesystem)/index.ts index 3917f2167..a0a998788 100644 --- a/src/lib/components/editor/(filesystem)/index.ts +++ b/src/lib/components/editor/(filesystem)/index.ts @@ -44,10 +44,16 @@ export function treeFromFilesystem(files: string[]): TreeItem[] { const tree: TreeItem[] = []; for (const path of files) { - const parts = path.split('/'); + const normalizedPath = path.endsWith('/') ? path.slice(0, -1) : path; + + if (!normalizedPath) continue; + + const parts = normalizedPath.split('/'); let currentLevel = tree; parts.forEach((part, index) => { + if (!part) return; + const existingItem = currentLevel.find((item) => item.title === part); if (existingItem) { @@ -56,7 +62,7 @@ export function treeFromFilesystem(files: string[]): TreeItem[] { } currentLevel = existingItem.children; } else { - const isFile = index === parts.length - 1; + const isFile = index === parts.length - 1 && !path.endsWith('/'); const currentPath = parts.slice(0, index + 1).join('/'); const newItem: TreeItem = { title: part, diff --git a/src/lib/components/editor/(filesystem)/tree.svelte b/src/lib/components/editor/(filesystem)/tree.svelte index d5c6c0bc9..edfb3d2f3 100644 --- a/src/lib/components/editor/(filesystem)/tree.svelte +++ b/src/lib/components/editor/(filesystem)/tree.svelte @@ -13,19 +13,19 @@ } = getContext('tree'); -{#each items as { title, icon, children, path }, i} - {@const hasChildren = !!children?.length} +{#each items as { title, icon, children, path } (path)} + {@const isFolder = children !== undefined} {@const isRoot = level === 1}