Snap this block to the nearest grid point.
()
| 459 | |
| 460 | /** Snap this block to the nearest grid point. */ |
| 461 | snapToGrid() { |
| 462 | if (this.isDeadOrDying()) return; |
| 463 | if (this.getParent()) return; |
| 464 | if (this.isInFlyout) return; |
| 465 | const grid = this.workspace.getGrid(); |
| 466 | if (!grid?.shouldSnap()) return; |
| 467 | const currentXY = this.getRelativeToSurfaceXY(); |
| 468 | const alignedXY = grid.alignXY(currentXY); |
| 469 | if (alignedXY !== currentXY) { |
| 470 | this.moveTo(alignedXY, ['snap']); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | /** |
| 475 | * Returns the coordinates of a bounding box describing the dimensions of this |
no test coverage detected