Skip to content

Commit e6ed9ae

Browse files
authored
Fix index crash in agent starter (tldraw#7048)
This PR pulls across a fix from fairydraw into the agent starter. ### Change type - [ ] `bugfix` - [ ] `improvement` - [ ] `feature` - [ ] `api` - [x] `other` ### Test plan 1. Create a shape... 2. - [ ] Unit tests - [ ] End to end tests ### Release notes - Agent starter: Fixed a bug where shape indices could get set to the same value. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Use the highest parent index for new shapes instead of a hardcoded value across all shape converters to avoid index collisions. > > - **templates/agent/shared/format/convertSimpleShapeToTldrawShape.ts**: > - **Index assignment**: When a shape's `index` is absent, use `editor.getHighestIndexForParent(editor.getCurrentPageId())` instead of the hardcoded `'a1'` for: > - `text`, `line`, `arrow`, `geo`, `note`, `draw`, and `unknown` shapes. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit d31e468. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 64d1b32 commit e6ed9ae

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

templates/agent/shared/format/convertSimpleShapeToTldrawShape.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ function convertTextShapeToTldrawShape(
198198
x: correctedTextCoords.x,
199199
y: correctedTextCoords.y,
200200
rotation: defaultTextShape.rotation ?? 0,
201-
index: defaultTextShape.index ?? ('a1' as IndexKey),
201+
index: defaultTextShape.index ?? editor.getHighestIndexForParent(editor.getCurrentPageId()),
202202
parentId: defaultTextShape.parentId ?? editor.getCurrentPageId(),
203203
isLocked: defaultTextShape.isLocked ?? false,
204204
opacity: defaultTextShape.opacity ?? 1,
@@ -242,7 +242,7 @@ function convertLineShapeToTldrawShape(
242242
x: minX,
243243
y: minY,
244244
rotation: defaultLineShape.rotation ?? 0,
245-
index: defaultLineShape.index ?? ('a1' as IndexKey),
245+
index: defaultLineShape.index ?? editor.getHighestIndexForParent(editor.getCurrentPageId()),
246246
parentId: defaultLineShape.parentId ?? editor.getCurrentPageId(),
247247
isLocked: defaultLineShape.isLocked ?? false,
248248
opacity: defaultLineShape.opacity ?? 1,
@@ -306,7 +306,7 @@ function convertArrowShapeToTldrawShape(
306306
x: minX,
307307
y: minY,
308308
rotation: defaultArrowShape.rotation ?? 0,
309-
index: defaultArrowShape.index ?? ('a1' as IndexKey),
309+
index: defaultArrowShape.index ?? editor.getHighestIndexForParent(editor.getCurrentPageId()),
310310
parentId: defaultArrowShape.parentId ?? editor.getCurrentPageId(),
311311
isLocked: defaultArrowShape.isLocked ?? false,
312312
opacity: defaultArrowShape.opacity ?? 1,
@@ -423,7 +423,7 @@ function convertGeoShapeToTldrawShape(
423423
x: simpleShape.x ?? defaultGeoShape.x ?? 0,
424424
y: simpleShape.y ?? defaultGeoShape.y ?? 0,
425425
rotation: defaultGeoShape.rotation ?? 0,
426-
index: defaultGeoShape.index ?? ('a1' as IndexKey),
426+
index: defaultGeoShape.index ?? editor.getHighestIndexForParent(editor.getCurrentPageId()),
427427
parentId: defaultGeoShape.parentId ?? editor.getCurrentPageId(),
428428
isLocked: defaultGeoShape.isLocked ?? false,
429429
opacity: defaultGeoShape.opacity ?? 1,
@@ -478,7 +478,7 @@ function convertNoteShapeToTldrawShape(
478478
x: simpleShape.x ?? defaultNoteShape.x ?? 0,
479479
y: simpleShape.y ?? defaultNoteShape.y ?? 0,
480480
rotation: defaultNoteShape.rotation ?? 0,
481-
index: defaultNoteShape.index ?? ('a1' as IndexKey),
481+
index: defaultNoteShape.index ?? editor.getHighestIndexForParent(editor.getCurrentPageId()),
482482
parentId: defaultNoteShape.parentId ?? editor.getCurrentPageId(),
483483
isLocked: defaultNoteShape.isLocked ?? false,
484484
opacity: defaultNoteShape.opacity ?? 1,
@@ -528,7 +528,7 @@ function convertDrawShapeToTldrawShape(
528528
x: defaultDrawShape.x ?? 0,
529529
y: defaultDrawShape.y ?? 0,
530530
rotation: defaultDrawShape.rotation ?? 0,
531-
index: defaultDrawShape.index ?? ('a1' as IndexKey),
531+
index: defaultDrawShape.index ?? editor.getHighestIndexForParent(editor.getCurrentPageId()),
532532
parentId: defaultDrawShape.parentId ?? editor.getCurrentPageId(),
533533
isLocked: defaultDrawShape.isLocked ?? false,
534534
opacity: defaultDrawShape.opacity ?? 1,
@@ -558,7 +558,7 @@ function convertUnknownShapeToTldrawShape(
558558
x: simpleShape.x ?? defaultShape.x ?? 0,
559559
y: simpleShape.y ?? defaultShape.y ?? 0,
560560
rotation: defaultShape.rotation ?? 0,
561-
index: defaultShape.index ?? ('a1' as IndexKey),
561+
index: defaultShape.index ?? editor.getHighestIndexForParent(editor.getCurrentPageId()),
562562
parentId: defaultShape.parentId ?? editor.getCurrentPageId(),
563563
isLocked: defaultShape.isLocked ?? false,
564564
opacity: defaultShape.opacity ?? 1,

0 commit comments

Comments
 (0)