mock: キー・部品を足したあと、足したノードを選ぶ
ツリーの最後のノードを新しいノードとみなしていたため、クラスター内に足すと ツリーでそれより後ろにある別のキーを選んでいた。追加前後のIDの差で特定する。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XsamNKrWY3obJwR746oQRq
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user