From 0d06827b692b9f8e0fd9d563f5c23e98c4032724 Mon Sep 17 00:00:00 2001 From: Miguel Palhas Date: Mon, 24 Aug 2026 15:51:19 +0100 Subject: [PATCH] fix(maestro): keep Enter toggling the worktree checkbox, not submitting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Matches the TUI's WorktreeToggle, whose Enter also toggles rather than submitting — otherwise the two clients would disagree on this one field despite #97 requiring the same rule everywhere else. --- web/src/spawnForm.ts | 9 +++++++++ web/src/spawnFormEnter.test.ts | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/web/src/spawnForm.ts b/web/src/spawnForm.ts index 39712cd..934b4ad 100644 --- a/web/src/spawnForm.ts +++ b/web/src/spawnForm.ts @@ -871,10 +871,19 @@ export function createSpawnForm(opts: SpawnFormOptions): SpawnFormHandle { // choose it instead; the next Enter, now that it's active, submits. // dirAutocomplete's own Enter (accept the highlight) already preventDefaults // when it handles the key, which the `e.defaultPrevented` guard defers to. + // The worktree checkbox keeps Enter as a toggle (TUI parity: `WorktreeToggle` + // does the same) rather than folding it into the blanket-submit rule below. form.addEventListener("keydown", (e) => { if (e.key !== "Enter" || e.defaultPrevented) return; const target = e.target as HTMLElement; + if (target === wtEnabled) { + e.preventDefault(); + wtEnabled.checked = !wtEnabled.checked; + wtEnabled.dispatchEvent(new Event("change")); + return; + } + if (target instanceof HTMLButtonElement) { if (!target.classList.contains("project-box") && !target.classList.contains("wt-choice")) return; e.preventDefault(); diff --git a/web/src/spawnFormEnter.test.ts b/web/src/spawnFormEnter.test.ts index a05c4b3..d856603 100644 --- a/web/src/spawnFormEnter.test.ts +++ b/web/src/spawnFormEnter.test.ts @@ -89,6 +89,24 @@ describe("spawnForm Enter-to-submit (#97)", () => { const box = (form: HTMLFormElement, path: string) => form.querySelector(`.project-box[data-cwd="${path}"]`)!; + it("toggles the worktree checkbox on Enter instead of submitting (TUI parity)", async () => { + const form = await mount([MAESTRO]); + box(form, MAESTRO.path).click(); + await drain(); + const toggle = form.querySelector("input[name=worktree_enabled]")!; + expect(toggle.checked).toBe(true); + const spy = submitSpy(); + form.addEventListener("submit", spy); + + pressEnter(toggle); + expect(toggle.checked).toBe(false); + expect(spy).not.toHaveBeenCalled(); + + pressEnter(toggle); + expect(toggle.checked).toBe(true); + expect(spy).not.toHaveBeenCalled(); + }); + describe("submits immediately from ordinary fields", () => { it("name field", async () => { const form = await mount([MAESTRO]);