From b501d2bd5cc95db1d3cf3bf8e8b187a605acf4e5 Mon Sep 17 00:00:00 2001 From: Yuri Karamian Date: Thu, 11 Jun 2026 22:56:54 +0200 Subject: [PATCH] Notebooks: add a collapse-all / expand-all button to the sidebar tree header (#26) --- src/lib/components/Sidebar.svelte | 60 ++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/src/lib/components/Sidebar.svelte b/src/lib/components/Sidebar.svelte index e72df07..964cf5f 100644 --- a/src/lib/components/Sidebar.svelte +++ b/src/lib/components/Sidebar.svelte @@ -67,6 +67,22 @@ $collapsedNotebooks = [...$collapsedNotebooks, path]; } } + // Collapse-all / expand-all: toggles every notebook that has children. + function collectParentPaths(tree: NotebookEntry[]): string[] { + const out: string[] = []; + for (const nb of tree) { + if (nb.children && nb.children.length > 0) { + out.push(nb.path); + out.push(...collectParentPaths(nb.children)); + } + } + return out; + } + const allParentPaths = $derived(collectParentPaths($notebooks)); + const allCollapsed = $derived(allParentPaths.length > 0 && allParentPaths.every((p) => $collapsedNotebooks.includes(p))); + function toggleAllCollapse() { + $collapsedNotebooks = allCollapsed ? [] : [...allParentPaths]; + } export async function refresh() { @@ -578,19 +594,32 @@ }} > Notebooks - +
+ {#if allParentPaths.length > 0} + + {/if} + +
{#if showNewNotebook} @@ -952,6 +981,11 @@ color: var(--text-tertiary); } + .section-actions { + display: flex; + align-items: center; + gap: 2px; + } .icon-btn, .icon-btn-sm { background: none; border: none;