diff --git a/dev-dashboard/frontend/src/App.svelte b/dev-dashboard/frontend/src/App.svelte index 2ddb228277..49f3d16402 100644 --- a/dev-dashboard/frontend/src/App.svelte +++ b/dev-dashboard/frontend/src/App.svelte @@ -17,9 +17,9 @@ let worktrees = $state([]); let selectedBranch = $state(null); let removeBranch = $state(null); + let removingBranches = $state>(new Set()); let showCreateDialog = $state(false); let creating = $state(false); - let removing = $state(false); let createProfile = $state("agent-only"); let visibleWorktrees = $derived( @@ -63,17 +63,26 @@ } async function handleRemove() { - if (!removeBranch) return; - removing = true; + const branch = removeBranch; + if (!branch) return; + removeBranch = null; + + // Select neighbor before starting the async removal + if (selectedBranch === branch) { + const idx = visibleWorktrees.findIndex((w) => w.branch === branch); + const neighbor = visibleWorktrees[idx - 1] ?? visibleWorktrees[idx + 1]; + const isNeighborMain = neighbor && (neighbor.path === "(here)" || neighbor.branch === "main"); + selectedBranch = neighbor && !isNeighborMain ? neighbor.branch : null; + } + + removingBranches = new Set([...removingBranches, branch]); try { - await api.removeWorktree(removeBranch); - if (selectedBranch === removeBranch) selectedBranch = null; - removeBranch = null; + await api.removeWorktree(branch); await refresh(); } catch (err) { alert(`Failed to remove: ${err instanceof Error ? err.message : err}`); } finally { - removing = false; + removingBranches = new Set([...removingBranches].filter((b) => b !== branch)); } } @@ -95,7 +104,7 @@ title="New Worktree" >+ New - (selectedBranch = b)} onremove={(b) => (removeBranch = b)} /> + (selectedBranch = b)} onremove={(b) => (removeBranch = b)} />
@@ -164,7 +173,6 @@ {#if removeBranch} (removeBranch = null)} /> diff --git a/dev-dashboard/frontend/src/lib/WorktreeList.svelte b/dev-dashboard/frontend/src/lib/WorktreeList.svelte index b4d009b0a6..665457e787 100644 --- a/dev-dashboard/frontend/src/lib/WorktreeList.svelte +++ b/dev-dashboard/frontend/src/lib/WorktreeList.svelte @@ -1,9 +1,10 @@