Commit 1ed9660
feat(editor): add selectLockedShapes option (tldraw#8860)
Adds a new `selectLockedShapes` option to `TldrawOptions` that, when
enabled, lets users select locked shapes with a left click (and via
brush or scribble selection). The editor's existing lock guards still
prevent moving, resizing, editing, or deleting locked shapes, so the
option enables inspection without unlocking.
When `selectLockedShapes: true`:
- `getHitShapeOnCanvasPointerDown` passes `hitLocked: true`
- `Idle.onPointerDown` no longer routes left clicks on locked shapes to
`pointing_canvas`
- `Brushing` and `ScribbleBrushing` include locked shapes
- Hover detection (`updateHoveredShapeId`) treats locked shapes as
hoverable
- `selectOnCanvasPointerUp` allows locked shapes through
When `selectLockedShapes` is `false` (default), behavior is unchanged.
Closes tldraw#8548
### Change type
- [ ] `bugfix`
- [ ] `improvement`
- [x] `feature`
- [ ] `api`
- [ ] `other`
### Test plan
1. Set `<Tldraw options={{ selectLockedShapes: true }} />` in an example
app.
2. Create a shape, lock it, and click it — it should become selected and
show selection bounds.
3. Try to drag or resize it — nothing should move (lock still applies).
4. Brush over the locked shape with the select tool — it should be
included in the brush selection.
5. Alt-drag (scribble select) over the locked shape — it should also be
included.
6. With the option set to `false` (default), confirm left-clicking a
locked shape still falls through to the canvas, matching the previous
behavior.
- [x] Unit tests
- [ ] End to end tests
### API changes
- Add a new `selectLockedShapes` option to `TldrawOptions` (and to
`defaultTldrawOptions`). When `false` (default), left-clicking a locked
shape is treated as a click on the canvas; only right-click selects it.
When `true`, locked shapes can be selected via left-click and included
in brush and scribble selections, but the editor's lock guards still
prevent moving, resizing, editing, or deleting them.
### Release notes
- Added a `selectLockedShapes` option to `TldrawOptions`. When enabled,
locked shapes can be selected with left click and brush/scribble
selection while remaining protected from edits, moves, and deletes.
---------
Co-authored-by: angrycaptain19 <53473467+angrycaptain19@users.noreply.github.com>1 parent d49babc commit 1ed9660
10 files changed
Lines changed: 154 additions & 25 deletions
File tree
- apps/examples/src/examples/editor-api/locked-shapes
- packages
- editor
- src/lib
- tldraw/src
- lib/tools
- SelectTool/childStates
- selection-logic
- test/commands
Lines changed: 65 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
17 | 31 | | |
18 | 32 | | |
19 | 33 | | |
| |||
46 | 60 | | |
47 | 61 | | |
48 | 62 | | |
49 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
50 | 78 | | |
51 | 79 | | |
52 | 80 | | |
| |||
61 | 89 | | |
62 | 90 | | |
63 | 91 | | |
64 | | - | |
| 92 | + | |
65 | 93 | | |
66 | 94 | | |
67 | 95 | | |
| |||
74 | 102 | | |
75 | 103 | | |
76 | 104 | | |
77 | | - | |
| 105 | + | |
78 | 106 | | |
79 | 107 | | |
80 | 108 | | |
| |||
92 | 120 | | |
93 | 121 | | |
94 | 122 | | |
95 | | - | |
| 123 | + | |
96 | 124 | | |
97 | 125 | | |
98 | 126 | | |
| |||
102 | 130 | | |
103 | 131 | | |
104 | 132 | | |
105 | | - | |
| 133 | + | |
| 134 | + | |
106 | 135 | | |
107 | | - | |
108 | | - | |
109 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
110 | 143 | | |
111 | 144 | | |
112 | 145 | | |
113 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
114 | 154 | | |
115 | | - | |
116 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
117 | 158 | | |
118 | | - | |
| 159 | + | |
119 | 160 | | |
120 | | - | |
| 161 | + | |
121 | 162 | | |
122 | | - | |
123 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
124 | 166 | | |
125 | 167 | | |
126 | | - | |
127 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
128 | 175 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
779 | 779 | | |
780 | 780 | | |
781 | 781 | | |
| 782 | + | |
782 | 783 | | |
783 | 784 | | |
784 | 785 | | |
| |||
3841 | 3842 | | |
3842 | 3843 | | |
3843 | 3844 | | |
| 3845 | + | |
3844 | 3846 | | |
3845 | 3847 | | |
3846 | 3848 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
174 | 181 | | |
175 | 182 | | |
176 | 183 | | |
| |||
335 | 342 | | |
336 | 343 | | |
337 | 344 | | |
| 345 | + | |
338 | 346 | | |
339 | 347 | | |
340 | 348 | | |
| |||
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
59 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
187 | | - | |
| 187 | + | |
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
245 | | - | |
| 245 | + | |
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
| |||
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
| 126 | + | |
| 127 | + | |
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
130 | | - | |
| 131 | + | |
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | | - | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
0 commit comments