From f64d632136d2ab5d2efc1f24fb339424aed43850 Mon Sep 17 00:00:00 2001 From: EwdErna Date: Fri, 23 Oct 2026 08:09:24 +0900 Subject: [PATCH] =?UTF-8?q?mock:=20=E3=82=AD=E3=83=BC=E3=83=BB=E9=83=A8?= =?UTF-8?q?=E5=93=81=E3=82=92=E8=B6=B3=E3=81=97=E3=81=9F=E3=81=82=E3=81=A8?= =?UTF-8?q?=E3=80=81=E8=B6=B3=E3=81=97=E3=81=9F=E3=83=8E=E3=83=BC=E3=83=89?= =?UTF-8?q?=E3=82=92=E9=81=B8=E3=81=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ツリーの最後のノードを新しいノードとみなしていたため、クラスター内に足すと ツリーでそれより後ろにある別のキーを選んでいた。追加前後のIDの差で特定する。 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XsamNKrWY3obJwR746oQRq --- mock/e2e/phy.spec.ts | 14 ++++++++++++++ mock/src/ui/phy/usePhyCommands.ts | 10 ++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/mock/e2e/phy.spec.ts b/mock/e2e/phy.spec.ts index f151337..91fcf5b 100644 --- a/mock/e2e/phy.spec.ts +++ b/mock/e2e/phy.spec.ts @@ -603,3 +603,17 @@ test("「その他」の部品はpartGroupを設定せず、選択後は追加 await expect(select).toHaveValue(""); await expect(page.locator('[data-node-type="component"] .part-label').last()).toHaveText("part"); }); + +test("クラスター内でキーを足すと、足したキーを選ぶ", async ({ page }) => { + const cluster = await makeCluster(page); + const clusterKeys = cluster.locator('[data-node-type="key"]'); + const before = await clusterKeys.evaluateAll((es) => es.map((e) => e.getAttribute("data-node-id"))); + await page.getByText("キー・部品 2件", { exact: true }).click(); + await page.locator(`[data-tree-id="${before[0]}"]`).first().click(); + await page.getByRole("button", { name: "キーを足す" }).click(); + await expect(clusterKeys).toHaveCount(3); + const after = await clusterKeys.evaluateAll((es) => es.map((e) => e.getAttribute("data-node-id"))); + const added = after.find((id) => !before.includes(id)); + await expect(page.locator(`[data-sel-id="${added}"]`)).toHaveCount(1); + await expect(page.locator("[data-sel-id]")).toHaveCount(1); +}); diff --git a/mock/src/ui/phy/usePhyCommands.ts b/mock/src/ui/phy/usePhyCommands.ts index 98603b6..f3ac57c 100644 --- a/mock/src/ui/phy/usePhyCommands.ts +++ b/mock/src/ui/phy/usePhyCommands.ts @@ -120,6 +120,12 @@ export function usePhyCommands(options: Options) { options.popover.value = null; } + /** The node id present in `after` but not in `before`; the tree order does not tell where it went. */ + function addedId(before: ProjectFile["phy"], after: ProjectFile["phy"]): string { + const existing = new Set(options.allNodes(before.root).map((node) => node.id)); + return options.allNodes(after.root).find((node) => !existing.has(node.id))?.id || ""; + } + function keyAdd() { const chosen = options.node(options.selected.value.at(-1) || ""); const parent = chosen ? options.selectedContainer(chosen.id) : insertionParent(); @@ -137,7 +143,7 @@ export function usePhyCommands(options: Options) { let id = ""; options.dispatch("キー追加", (project) => { const phy = addKeyToParent(project.phy, parent, { x, y, rotation: 0 }, { w: 1, h: 1 }); - id = options.allNodes(phy.root).at(-1)?.id || ""; + id = addedId(project.phy, phy); return { ...project, phy, idx: { ...project.idx, order: [...project.idx.order, id] } }; }); if (id) options.selected.value = [id]; @@ -171,7 +177,7 @@ export function usePhyCommands(options: Options) { { x, y, rotation: 0 }, group === "その他" ? undefined : group, ); - id = options.allNodes(phy.root).at(-1)?.id || ""; + id = addedId(project.phy, phy); return { ...project, phy }; }); if (id) options.selected.value = [id];