Skip to content

Commit 9caa949

Browse files
authored
fix(tldraw): fix reparenting in groups after a deletion (tldraw#8925)
Closes tldraw#8857 Deleting a shape in a group made the reparenting to repop the group at a different z-index, this should not happen and the group should keep the same index it previously owned ### Change type - [x] `bugfix` - [ ] `improvement` - [ ] `feature` - [ ] `api` - [ ] `other` ### Test plan Described in tldraw#8857 - [ ] Unit tests - [ ] End to end tests ### Release notes - Fixed an issue with deleting shapes in a group that caused a reparenting of the group at a different z-index
1 parent 84056a8 commit 9caa949

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

packages/editor/src/lib/editor/shapes/group/GroupShapeUtil.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class GroupShapeUtil extends ShapeUtil<TLGroupShape> {
133133
if (this.editor.getCurrentPageState().focusedGroupId === group.id) {
134134
this.editor.popFocusedGroupId()
135135
}
136-
this.editor.reparentShapes(children, group.parentId)
136+
this.editor.reparentShapes(children, group.parentId, group.index)
137137
this.editor.deleteShapes([group.id])
138138
return
139139
}

packages/tldraw/src/test/groups.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,22 @@ describe("when a group's children are deleted", () => {
11571157
expect(editor.getShape(groupCId)).toBeUndefined()
11581158
expect(editor.getShape(groupAId)).not.toBeUndefined()
11591159
})
1160+
1161+
it('preserves the collapsed group z-index when reparenting the last child', () => {
1162+
// Page contains: groupC (lower) then boxX (on top). Deleting boxA collapses
1163+
// groupA inside groupC, so boxB should take groupA's z-index in groupC and
1164+
// stay below groupB instead of jumping to the top of groupC's children.
1165+
editor.createShapes([box(ids.boxX, 80, 0)])
1166+
1167+
const pageId = editor.getCurrentPageId()
1168+
expect(editor.getSortedChildIdsForParent(pageId)).toEqual([groupCId, ids.boxX])
1169+
expect(editor.getSortedChildIdsForParent(groupCId)).toEqual([groupAId, groupBId])
1170+
1171+
editor.deleteShapes([ids.boxA])
1172+
1173+
expect(editor.getShape(groupAId)).toBeUndefined()
1174+
expect(editor.getSortedChildIdsForParent(groupCId)).toEqual([ids.boxB, groupBId])
1175+
})
11601176
})
11611177

11621178
describe('creating new shapes', () => {

0 commit comments

Comments
 (0)