MCPcopy
hub / github.com/tldraw/tldraw / setSelectedShapes

Method setSelectedShapes

packages/editor/src/lib/editor/Editor.ts:2068–2081  ·  view source on GitHub ↗

* Select one or more shapes. * * @example * ```ts * editor.setSelectedShapes(['id1']) * editor.setSelectedShapes(['id1', 'id2']) * ``` * * @param shapes - The shape (or shape ids) to select. * * @public

(shapes: TLShapeId[] | TLShape[])

Source from the content-addressed store, hash-verified

2066 * @public
2067 */
2068 setSelectedShapes(shapes: TLShapeId[] | TLShape[]): this {
2069 return this.run(
2070 () => {
2071 const ids = shapes.map((shape) => (typeof shape === 'string' ? shape : shape.id))
2072 const { selectedShapeIds: prevSelectedShapeIds } = this.getCurrentPageState()
2073 const prevSet = new Set(prevSelectedShapeIds)
2074
2075 if (ids.length === prevSet.size && ids.every((id) => prevSet.has(id))) return null
2076
2077 this.store.put([{ ...this.getCurrentPageState(), selectedShapeIds: ids }])
2078 },
2079 { history: 'record-preserveRedoStack' }
2080 )
2081 }
2082
2083 /**
2084 * Determine whether or not any of a shape's ancestors are selected.

Callers 15

selectMethod · 0.95
deselectMethod · 0.95
selectAllMethod · 0.95
_selectShapesAndZoomMethod · 0.95
selectNoneMethod · 0.95
duplicateShapesMethod · 0.95
toggleLockMethod · 0.95
_flushEventForTickMethod · 0.95
completeMethod · 0.80
selectOnCanvasPointerUpFunction · 0.80
onEnterMethod · 0.80
onPointerUpMethod · 0.80

Calls 4

runMethod · 0.95
getCurrentPageStateMethod · 0.95
putMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected