1/6
Easy++#patchexcalidrawframesz-ordercollaboration

Ignore deleted children when placing new frame children

excalidraw/excalidraw#12510 · @dwelle · MIT · licence

description
- Deleted frame children keep their frameId and index. One left above its frame made new children of that frame (drawn, or dragged into it) go above it, up to the top of the canvas. - A reload fixed it locally, since localStorage drops deleted elements. In collab rooms deleted elements are kept for 24h, so it persisted, and clients with different deleted elements in memory placed the same insert differently. - getFrameChildrenInsertionIndex now skips deleted children. The index still points into the full array, deleted elements included, so fractional indices stay valid. The drag-into-frame preview already ignored deleted elements, so the drop now lands where the preview showed. - Unchanged: undoing a deletion still restores the element at its old index, and a live child above its frame still takes new children above it (the existing fallback). Claude Opus 5.5 (xhigh)
1 commit · 2 files
  • 68d1d4afix(editor): place new frame children below the frame despite deleted children

// files changed

Mpackages/element/src/frame.ts+3−1
@@ -553,7 +553,9 @@ export const getFrameChildrenInsertionIndex = (
553553
554554 if (element.id === frameId) {
555555 return index;
556 } else if (element.frameId === frameId) {
556 } else if (element.frameId === frameId && !element.isDeleted) {
557 // deleted children keep their frameId (and index), but don't count:
558 // they'd place the new ones as high as they were
557559 return index + 1;
558560 }
559561 }
Mpackages/element/tests/frame.test.tsx+44−0
@@ -439,6 +439,50 @@ describe("adding elements to frames", () => {
439439 ]);
440440 });
441441
442 it("should insert a newly created frame child below its frame despite deleted frame children above it", () => {
443 const frameChild = API.createElement({
444 id: "frameChild",
445 type: "rectangle",
446 x: 100,
447 y: 20,
448 width: 20,
449 height: 20,
450 frameId: frame.id,
451 });
452 const deletedFrameChild = API.createElement({
453 id: "deletedFrameChild",
454 type: "rectangle",
455 x: 100,
456 y: 60,
457 width: 20,
458 height: 20,
459 frameId: frame.id,
460 isDeleted: true,
461 });
462
463 API.setElements([frameChild, frame, deletedFrameChild]);
464
465 UI.clickTool("rectangle");
466 mouse.downAt(20, 20);
467 mouse.moveTo(40, 40);
468 mouse.upAt(40, 40);
469
470 const createdElement = h.elements.find(
471 (element) =>
472 element.id !== frame.id &&
473 element.id !== frameChild.id &&
474 element.id !== deletedFrameChild.id,
475 );
476
477 expect(createdElement?.frameId).toBe(frame.id);
478 expect(h.elements.map((element) => element.id)).toEqual([
479 frameChild.id,
480 createdElement?.id,
481 frame.id,
482 deletedFrameChild.id,
483 ]);
484 });
485
442486 it("should insert a newly created frame child above the highest frame child", () => {
443487 const frameChildUnderCursor = API.createElement({
444488 id: "frameChildUnderCursor",