fix(editor): ignore deleted elements when inserting frame children (#12510)

fix(editor): place new frame children below the frame despite deleted children

Deleted frame children keep their frameId and index, so one left above the
frame made new children of that frame (created or dragged in) go above it,
up to the top of the canvas, until a reload dropped the deleted elements.
Only live children count now.

Claude Opus 5.5 (xhigh)
This commit is contained in:
David Luzar authored and GitHub committed 2026-10-31 17:48:47 +01:00
1 parent 2610ebae0c
commit 8bcdca4526
2 files changed
+47 -1

No files matched your search

+3 -1
View File
@@ -553,7 +553,9 @@ export const getFrameChildrenInsertionIndex = (
if (element.id === frameId) {
return index;
} else if (element.frameId === frameId) {
} else if (element.frameId === frameId && !element.isDeleted) {
// deleted children keep their frameId (and index), but don't count:
// they'd place the new ones as high as they were
return index + 1;
}
}
+44
View File
@@ -439,6 +439,50 @@ describe("adding elements to frames", () => {
]);
});
it("should insert a newly created frame child below its frame despite deleted frame children above it", () => {
const frameChild = API.createElement({
id: "frameChild",
type: "rectangle",
x: 100,
y: 20,
width: 20,
height: 20,
frameId: frame.id,
});
const deletedFrameChild = API.createElement({
id: "deletedFrameChild",
type: "rectangle",
x: 100,
y: 60,
width: 20,
height: 20,
frameId: frame.id,
isDeleted: true,
});
API.setElements([frameChild, frame, deletedFrameChild]);
UI.clickTool("rectangle");
mouse.downAt(20, 20);
mouse.moveTo(40, 40);
mouse.upAt(40, 40);
const createdElement = h.elements.find(
(element) =>
element.id !== frame.id &&
element.id !== frameChild.id &&
element.id !== deletedFrameChild.id,
);
expect(createdElement?.frameId).toBe(frame.id);
expect(h.elements.map((element) => element.id)).toEqual([
frameChild.id,
createdElement?.id,
frame.id,
deletedFrameChild.id,
]);
});
it("should insert a newly created frame child above the highest frame child", () => {
const frameChildUnderCursor = API.createElement({
id: "frameChildUnderCursor",