diff --git a/src/routes/(editor)/edit.tsx b/src/routes/(editor)/edit.tsx index 57542ba..c959727 100644 --- a/src/routes/(editor)/edit.tsx +++ b/src/routes/(editor)/edit.tsx @@ -61,12 +61,12 @@ const Editor: Component<{ root: FileSystemDirectoryHandle }> = (props) => { const tabs = createMemo(() => filesContext.files().map(({ key, handle }) => { const [api, setApi] = createSignal(); const [entries, setEntries] = createSignal(new Map()); - const [files, setFiles] = createSignal>(new Map()); + const [files, setFiles] = createSignal>(new Map()); (async () => { const files = await Array.fromAsync( filter(handle.values(), entry => entry.kind === 'file'), - async file => [file.name.split('.').at(0)!, { handle: file, key: await file.getUniqueId() }] as const + async file => [file.name.split('.').at(0)!, { handle: file, id: await file.getUniqueId() }] as const ); setFiles(new Map(files)); @@ -80,6 +80,7 @@ const Editor: Component<{ root: FileSystemDirectoryHandle }> = (props) => { const tab = createMemo(() => { const name = active(); + return tabs().find(t => t.handle.name === name); }); const api = createMemo(() => tab()?.api()); @@ -145,17 +146,24 @@ const Editor: Component<{ root: FileSystemDirectoryHandle }> = (props) => { handle, existing.entries().reduce((aggregate, [key, value]) => { let obj = aggregate; - const [k, lastPart] = splitAt(key, key.lastIndexOf('.')); + const i = key.lastIndexOf('.'); - for (const part of k.split('.')) { - if (!Object.hasOwn(obj, part)) { - obj[part] = {}; + if (i !== -1) { + const [k, lastPart] = splitAt(key, i); + + for (const part of k.split('.')) { + if (!Object.hasOwn(obj, part)) { + obj[part] = {}; + } + + obj = obj[part]; } - obj = obj[part]; + obj[lastPart] = value; + } + else { + obj[key] = value; } - - obj[lastPart] = value; return aggregate; }, {} as Record) @@ -172,14 +180,6 @@ const Editor: Component<{ root: FileSystemDirectoryHandle }> = (props) => { })(); }); - createEffect(() => { - console.log(mutatedFiles()); - }); - - createEffect(() => { - console.log(mutatedData()); - }); - const [prompt, setPrompt] = createSignal(); const commands = {