Fix bug on group cloning (#196)

This commit is contained in:
Steve Ruiz 2021-10-22 13:23:36 +01:00 committed by GitHub
parent ad8bf78dd4
commit dd4f39ae74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View file

@ -298,6 +298,21 @@ describe('Translate session', () => {
.updateSession([20, 20], false, false)
.updateSession([20, 20], false, true)
.completeSession()
expect(tlstate.shapes.filter((shape) => shape.type === TLDrawShapeType.Group).length).toBe(2)
})
it('deletes clones when not cloning anymore', () => {
tlstate
.loadDocument(mockDocument)
.select('rect1', 'rect2')
.group()
.startSession(SessionType.Translate, [10, 10])
.updateSession([20, 20], false, true)
.updateSession([20, 20], false, false)
.completeSession()
expect(tlstate.shapes.filter((shape) => shape.type === TLDrawShapeType.Group).length).toBe(1)
})
it('clones the shapes and children when selecting a group and a different shape', () => {

View file

@ -12,6 +12,7 @@ import {
GroupShape,
SessionType,
ArrowBinding,
TLDrawShapeType,
} from '~types'
import { SLOW_SPEED, SNAP_DISTANCE } from '~state/constants'
import { TLDR } from '~state/tldr'
@ -273,9 +274,8 @@ export class TranslateSession extends Session {
bindingsToDelete.forEach((binding) => (nextBindings[binding.id] = undefined))
// Delete the clones
// Remove the clones from parents
clones.forEach((clone) => {
nextShapes[clone.id] = undefined
if (clone.parentId !== currentPageId) {
nextShapes[clone.parentId] = {
...nextShapes[clone.parentId],
@ -284,6 +284,9 @@ export class TranslateSession extends Session {
}
})
// Delete the clones (including any parent clones)
clones.forEach((clone) => (nextShapes[clone.id] = undefined))
// Move the original shapes back to the cursor position
initialShapes.forEach((shape) => {
nextShapes[shape.id] = {