MCPcopy
hub / github.com/tldraw/tldraw / selectAll

Method selectAll

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

* Select all shapes. If the user has selected shapes that share a parent, * select all shapes within that parent. If the user has not selected any shapes, * or if the shapes shapes are only on select all shapes on the current page. * * @example * ```ts * editor.selectAll() * ``` *

()

Source from the content-addressed store, hash-verified

2152 * @public
2153 */
2154 selectAll(): this {
2155 let parentToSelectWithinId: TLParentId | null = null
2156
2157 const selectedShapeIds = this.getSelectedShapeIds()
2158
2159 // If we have selected shapes, try to find a parent to select within
2160 if (selectedShapeIds.length > 0) {
2161 for (const id of selectedShapeIds) {
2162 const shape = this.getShape(id)
2163 if (!shape) continue
2164 if (parentToSelectWithinId === null) {
2165 // If we haven't found a parent yet, set this parent as the parent to select within
2166 parentToSelectWithinId = shape.parentId
2167 } else if (parentToSelectWithinId !== shape.parentId) {
2168 // If we've found two different parents, we can't select all, do nothing
2169 return this
2170 }
2171 }
2172 }
2173
2174 // If we haven't found a parent from our selected shapes, select the current page
2175 if (!parentToSelectWithinId) {
2176 parentToSelectWithinId = this.getCurrentPageId()
2177 }
2178
2179 // Select all the unlocked shapes within the parent
2180 const ids = this.getSortedChildIdsForParent(parentToSelectWithinId)
2181 if (ids.length <= 0) return this
2182 this.setSelectedShapes(this._getUnlockedShapeIds(ids))
2183 return this
2184 }
2185
2186 /**
2187 * Select the next shape in the reading order or in cardinal order.

Callers 15

Editor.test.tsFile · 0.80
buildFromV1DocumentFunction · 0.80
initFunction · 0.80
RichTextArea.tsxFile · 0.80
onSelectFunction · 0.80
duplicate.test.tsFile · 0.80

Calls 6

getSelectedShapeIdsMethod · 0.95
getShapeMethod · 0.95
getCurrentPageIdMethod · 0.95
setSelectedShapesMethod · 0.95
_getUnlockedShapeIdsMethod · 0.95

Tested by 2

initFunction · 0.64
measureLineBandsFunction · 0.64