Skip to content

Commit 3819c8d

Browse files
authored
Fix pin example reparenting (tldraw#7206)
Fixes tldraw#6607 ### Change type - [ ] `bugfix` - [ ] `improvement` - [ ] `feature` - [ ] `api` - [x] `other` <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Reparents a pin to the bound shape’s new parent when the target shape changes, updating the `onAfterChangeToShape` handler to access `shapeAfter`. > > - **Pin bindings example (`apps/examples/src/examples/pin-bindings/PinExample.tsx`)**: > - Update `onAfterChangeToShape` signature to include `shapeAfter`. > - Reparent pin (`fromId`) to follow the bound shape’s (`toId`) new `parentId` when it changes. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 733bbed. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent ec6b950 commit 3819c8d

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

apps/examples/src/examples/pin-bindings/PinExample.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,18 @@ class PinBindingUtil extends BindingUtil<PinBinding> {
274274
}
275275

276276
// when the shape we're stuck to changes, update the pin's position
277-
override onAfterChangeToShape({ binding }: BindingOnShapeChangeOptions<PinBinding>): void {
277+
override onAfterChangeToShape({
278+
binding,
279+
shapeAfter,
280+
}: BindingOnShapeChangeOptions<PinBinding>): void {
278281
this.changedToShapes.add(binding.toId)
282+
const pin = this.editor.getShape(binding.fromId)
283+
if (!pin) return
284+
285+
// If the bound shape changed parents, reparent the pin to follow
286+
if (pin.parentId !== shapeAfter.parentId) {
287+
this.editor.reparentShapes([pin.id], shapeAfter.parentId)
288+
}
279289
}
280290

281291
// when the thing we're stuck to is deleted, delete the pin too

0 commit comments

Comments
 (0)