diff --git a/birdie/src/routes/+page.svelte b/birdie/src/routes/+page.svelte index cfc76ef..5b3fe5b 100644 --- a/birdie/src/routes/+page.svelte +++ b/birdie/src/routes/+page.svelte @@ -429,7 +429,10 @@ const goBack = async (index: number) => { ancestry = ancestry.slice(0, index + 1); $currentRoot = ancestry.join('/'); - $selectedFile = null; + + const parentFiles = await getFiles(ancestry.slice(0, index).join('/')); + $selectedFile = parentFiles.find((f) => f.name === ancestry[index]) ?? null; + commits = []; selectedFiles = []; await refreshFiles(); @@ -566,12 +569,12 @@ }); }; - const addCurrentRootToFileTree = async (node: Node, subFolders: string[]): Promise => { + const addSelectedFilePathToFileTree = async (node: Node, subFolders: string[]): Promise => { if (node.value.fileType === FileType.File) return node; const updatedChildFiles = await getFiles(node.value.path); let updatedChildNodes: Node[] = []; if (subFolders.length === 0) { - // we're at the deepest level of the current root + // we're at the deepest subfolder level // update our children and "forget" anything deeper than this updatedChildFiles.forEach((child) => { updatedChildNodes.push({ @@ -601,7 +604,7 @@ updatedChildNodes = await Promise.all( updatedChildNodes.map((child) => { if (child.value.name === subFolders[0]) { - return addCurrentRootToFileTree(child, subFolders.slice(1)); + return addSelectedFilePathToFileTree(child, subFolders.slice(1)); } return child; }) @@ -619,7 +622,7 @@ rootNode.set(parsedFileTree); } if ($selectedFile) { - $rootNode = await addCurrentRootToFileTree(get(rootNode), $selectedFile.path.split('/')); + $rootNode = await addSelectedFilePathToFileTree(get(rootNode), $selectedFile.path.split('/')); } };