* 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[])
| 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. |
no test coverage detected