diff --git a/web/src/multiview.test.ts b/web/src/multiview.test.ts index 8067d5e..36e2a09 100644 --- a/web/src/multiview.test.ts +++ b/web/src/multiview.test.ts @@ -147,6 +147,48 @@ describe("multiview openDraft (#62)", () => { expect((mv.el.querySelector(".mv-draft input[name=name]") as HTMLInputElement).value).toBe("wip"); }); + it("reuses an already-synced empty pane instead of splitting (#72)", async () => { + const layout = emptyLayout(); + const tab = layout.tabs[0]; + const first = splitLeaf(tab, "", "s1", "row", true); + const empty = splitLeaf(tab, first, null, "row", true); + tab.focusedLeafId = empty; + const mv = makeMv(layout); + document.body.appendChild(mv.el); + mv.render(); + // Let the mounted form's loadProjects() settle and auto-sync its picked + // defaults into leaf.draft before openDraft runs (#72's dead-branch window). + await flush(); + expect(leaves(tab.root).find((l) => l.id === empty)?.draft).not.toBeNull(); + + mv.openDraft(); + await flush(); + + expect(leaves(tab.root)).toHaveLength(2); + expect(tab.focusedLeafId).toBe(empty); + }); + + it("keeps a seed after reusing an already-synced empty pane (#72)", async () => { + const layout = emptyLayout(); + const tab = layout.tabs[0]; + const first = splitLeaf(tab, "", "s1", "row", true); + const empty = splitLeaf(tab, first, null, "row", true); + tab.focusedLeafId = empty; + const mv = makeMv(layout); + document.body.appendChild(mv.el); + mv.render(); + await flush(); + + mv.openDraft({ cwd: "/home/user/proj", command: "claude" }); + await flush(); + + const leaf = leaves(tab.root).find((l) => l.id === empty)!; + expect(leaf.draft?.cwd).toBe("/home/user/proj"); + expect(leaf.draft?.command).toBe("claude"); + const cwdRaw = mv.el.querySelector(".mv-draft .cwd-raw") as HTMLInputElement; + expect(cwdRaw.value).toBe("/home/user/proj"); + }); + it("seeds a clone's cwd and command into the draft", async () => { const layout = emptyLayout(); const mv = makeMv(layout); diff --git a/web/src/multiview.ts b/web/src/multiview.ts index b837c6e..cfd00b9 100644 --- a/web/src/multiview.ts +++ b/web/src/multiview.ts @@ -423,9 +423,15 @@ export function createMultiView(opts: MultiViewOptions): MultiView { return; } const target = findLeaf(tab.root, tab.focusedLeafId)!; - if (!target.sessionId && !target.draft) { - // An already-empty pane becomes the draft in place. + if (!target.sessionId) { + // Empty = no session, not `!draft` (#72): the mounted form auto-syncs + // picked defaults into `draft` once ready, so that's never reliably null. target.draft = draft(); + const stale = draftForms.get(target.id); + if (stale) { + stale.destroy(); + draftForms.delete(target.id); + } } else { // Split a fresh draft beside the focused pane. tab.focusedLeafId = splitLeaf(tab, target.id, null, "row", true);