Fix bug with duplicate children in clones
This commit is contained in:
parent
fe9ff2dc2d
commit
b48e2bf03f
3 changed files with 28 additions and 5 deletions
|
@ -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],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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],
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue