Skip to content

Commit

Permalink
fix: pasting group shape issue
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 authored and tiensonqin committed Dec 19, 2022
1 parent d6bd495 commit 54fb5ef
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions tldraw/packages/core/src/lib/TLApi/TLApi.ts
Expand Up @@ -219,14 +219,16 @@ export class TLApi<S extends TLShape = TLShape, K extends TLEventMap = TLEventMa
bindings: Record<string, TLBinding>
}) => {
const commonBounds = BoundsUtils.getCommonBounds(
shapes.map(shape => ({
minX: shape.point?.[0] ?? point[0],
minY: shape.point?.[1] ?? point[1],
width: shape.size?.[0] ?? 4,
height: shape.size?.[1] ?? 4,
maxX: (shape.point?.[0] ?? point[0]) + (shape.size?.[0] ?? 4),
maxY: (shape.point?.[1] ?? point[1]) + (shape.size?.[1] ?? 4),
}))
shapes
.filter(s => s.type !== 'group')
.map(shape => ({
minX: shape.point?.[0] ?? point[0],
minY: shape.point?.[1] ?? point[1],
width: shape.size?.[0] ?? 4,
height: shape.size?.[1] ?? 4,
maxX: (shape.point?.[0] ?? point[0]) + (shape.size?.[0] ?? 4),
maxY: (shape.point?.[1] ?? point[1]) + (shape.size?.[1] ?? 4),
}))
)

const clonedShapes = shapes.map(shape => {
Expand All @@ -242,9 +244,9 @@ export class TLApi<S extends TLShape = TLShape, K extends TLEventMap = TLEventMa

clonedShapes.forEach(s => {
if (s.children && s.children?.length > 0) {
s.children = s.children.map(oldId => {
return clonedShapes[shapes.findIndex(s => s.id === oldId)].id
})
s.children = s.children
.map(oldId => clonedShapes[shapes.findIndex(s => s.id === oldId)]?.id)
.filter(isNonNullable)
}
})

Expand Down

0 comments on commit 54fb5ef

Please sign in to comment.