Commit e125b3a
authored
fix(tldraw): don't steal selection when pasting mid-interaction (tldraw#8976)
## Overview
In order to keep an in-progress interaction intact when content is
pasted mid-gesture, this PR stops `defaultHandleExternalTldrawContent`
from selecting the pasted shapes while the user is dragging a handle,
translating, resizing, or rotating.
This is an **alternative** to tldraw#8968 for the same underlying problem
(tldraw#8305). Where tldraw#8968 keeps the binding-hint overlay alive by gating the
overlay's `isActive`/`getOverlays` on the interaction state, this PR
instead avoids the root cause for the paste case: the pasted content no
longer steals selection from the shape being manipulated. Opened as a
draft so the two approaches can be compared side by side.
When the user pastes tldraw content while mid-interaction — for example
dragging an arrow's endpoint handle — the default handler used to
`select` the newly pasted shapes. That stole selection from the shape
under manipulation and interrupted the gesture (the arrow's in-progress
binding hint, for instance, disappeared until the drag ended). With this
change the selection is left untouched while mid-interaction, so the
gesture continues uninterrupted. When not mid-interaction, paste still
selects the pasted content as before.
Because we no longer reselect mid-interaction, the selection bounds
before and after paste are identical, which would make the paste "puff"
overlap check always pass. The puff is meant to signal that the
newly-selected pasted content landed on the old selection, so it's now
skipped while mid-interaction.
## Scope note
The known undo-grouping quirk tracked in tldraw#8969 (paste landing in the
same undo entry as the drag) is **intentionally left out of scope**
here, to keep this change focused and comparable to tldraw#8968.
Thanks to @SomeHats for suggesting this approach in
tldraw#8968 (comment).
## Change type
- [x] `bugfix`
## Test plan
1. Create a shape and an arrow bound to it.
2. Start dragging the arrow's free endpoint handle.
3. While still dragging, paste some tldraw content.
4. The arrow stays selected and its binding hint remains visible; the
pasted content is added without stealing selection.
5. Paste while idle — the pasted content is selected as normal.
- [x] Unit tests added in `SelectTool.test.ts` covering dragging a
handle, translating, resizing, the no-puff case, and the idle
(still-selects) case.
## Release notes
- Pasting content while dragging, translating, resizing, or rotating no
longer steals selection from the shape being manipulated.
## Code changes
| Area | Files | +/- |
| --- | --- | --- |
| Core | `defaultExternalContentHandlers.ts` | +19/-1 |
| Tests | `SelectTool.test.ts` | +134/-0 |
Relates to tldraw#8305. Alternative to tldraw#8968.1 parent c49c3e8 commit e125b3a
2 files changed
Lines changed: 155 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
624 | 624 | | |
625 | 625 | | |
626 | 626 | | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
627 | 639 | | |
628 | 640 | | |
629 | | - | |
| 641 | + | |
630 | 642 | | |
631 | 643 | | |
632 | 644 | | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
633 | 652 | | |
634 | 653 | | |
635 | 654 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
261 | 262 | | |
262 | 263 | | |
263 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 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 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
264 | 399 | | |
265 | 400 | | |
266 | 401 | | |
| |||
0 commit comments