Fix bug with duplicate children in clones

This commit is contained in:
Steve Ruiz 2021-09-02 21:29:45 +01:00
parent fe9ff2dc2d
commit b48e2bf03f
3 changed files with 28 additions and 5 deletions

View file

@ -183,21 +183,31 @@ export function group(
before: {
document: {
pages: {
[data.appState.currentPageId]: {
[currentPageId]: {
shapes: beforeShapes,
bindings: beforeBindings,
},
},
pageStates: {
[currentPageId]: {
selectedIds: TLDR.getSelectedIds(data, currentPageId),
},
},
},
},
after: {
document: {
pages: {
[data.appState.currentPageId]: {
[currentPageId]: {
shapes: afterShapes,
bindings: beforeBindings,
},
},
pageStates: {
[currentPageId]: {
selectedIds: [groupId],
},
},
},
},
}

View file

@ -204,5 +204,16 @@ describe('Translate session', () => {
.updateTranslateSession([20, 20], false, true)
.completeSession()
})
it('clones the shapes and children when selecting a group and a different shape', () => {
tlstate
.loadDocument(mockDocument)
.select('rect1', 'rect2')
.group(['rect1', 'rect2'], 'groupA')
.select('groupA', 'rect3')
.startTranslateSession([10, 10])
.updateTranslateSession([20, 20], false, true)
.completeSession()
})
})
})

View file

@ -94,9 +94,11 @@ export class TranslateSession implements Session {
const children =
nextShapes[clone.parentId]?.children || initialParentChildren[clone.parentId]
nextShapes[clone.parentId] = {
...nextShapes[clone.parentId],
children: [...children, clone.id],
if (!children.includes(clone.id)) {
nextShapes[clone.parentId] = {
...nextShapes[clone.parentId],
children: [...children, clone.id],
}
}
}
})