Browse Source

Fix bug on group cloning (#196)

main
Steve Ruiz 3 years ago
parent
commit
dd4f39ae74
No account linked to committer's email address

+ 15
- 0
packages/tldraw/src/state/session/sessions/translate/translate.session.spec.ts View File

@@ -298,6 +298,21 @@ describe('Translate session', () => {
298 298
         .updateSession([20, 20], false, false)
299 299
         .updateSession([20, 20], false, true)
300 300
         .completeSession()
301
+
302
+      expect(tlstate.shapes.filter((shape) => shape.type === TLDrawShapeType.Group).length).toBe(2)
303
+    })
304
+
305
+    it('deletes clones when not cloning anymore', () => {
306
+      tlstate
307
+        .loadDocument(mockDocument)
308
+        .select('rect1', 'rect2')
309
+        .group()
310
+        .startSession(SessionType.Translate, [10, 10])
311
+        .updateSession([20, 20], false, true)
312
+        .updateSession([20, 20], false, false)
313
+        .completeSession()
314
+
315
+      expect(tlstate.shapes.filter((shape) => shape.type === TLDrawShapeType.Group).length).toBe(1)
301 316
     })
302 317
 
303 318
     it('clones the shapes and children when selecting a group and a different shape', () => {

+ 5
- 2
packages/tldraw/src/state/session/sessions/translate/translate.session.ts View File

@@ -12,6 +12,7 @@ import {
12 12
   GroupShape,
13 13
   SessionType,
14 14
   ArrowBinding,
15
+  TLDrawShapeType,
15 16
 } from '~types'
16 17
 import { SLOW_SPEED, SNAP_DISTANCE } from '~state/constants'
17 18
 import { TLDR } from '~state/tldr'
@@ -273,9 +274,8 @@ export class TranslateSession extends Session {
273 274
 
274 275
         bindingsToDelete.forEach((binding) => (nextBindings[binding.id] = undefined))
275 276
 
276
-        // Delete the clones
277
+        // Remove the clones from parents
277 278
         clones.forEach((clone) => {
278
-          nextShapes[clone.id] = undefined
279 279
           if (clone.parentId !== currentPageId) {
280 280
             nextShapes[clone.parentId] = {
281 281
               ...nextShapes[clone.parentId],
@@ -284,6 +284,9 @@ export class TranslateSession extends Session {
284 284
           }
285 285
         })
286 286
 
287
+        // Delete the clones (including any parent clones)
288
+        clones.forEach((clone) => (nextShapes[clone.id] = undefined))
289
+
287 290
         // Move the original shapes back to the cursor position
288 291
         initialShapes.forEach((shape) => {
289 292
           nextShapes[shape.id] = {

Loading…
Cancel
Save