* Bumps unconnected blocks out of alignment. * * Two blocks which aren't actually connected should not coincidentally line * up on screen, because that creates confusion for end-users.
()
| 1647 | * up on screen, because that creates confusion for end-users. |
| 1648 | */ |
| 1649 | override bumpNeighbours() { |
| 1650 | const root = this.getRootBlock(); |
| 1651 | if ( |
| 1652 | this.isDeadOrDying() || |
| 1653 | this.workspace.isDragging() || |
| 1654 | this.isDragging() || |
| 1655 | root.isInFlyout |
| 1656 | ) { |
| 1657 | return; |
| 1658 | } |
| 1659 | |
| 1660 | function neighbourIsInStack(neighbour: RenderedConnection) { |
| 1661 | return neighbour.getSourceBlock().getRootBlock() === root; |
| 1662 | } |
| 1663 | |
| 1664 | for (const conn of this.getConnections_(false)) { |
| 1665 | if (conn.isSuperior()) { |
| 1666 | // Recurse down the block stack. |
| 1667 | conn.targetBlock()?.bumpNeighbours(); |
| 1668 | } |
| 1669 | |
| 1670 | for (const neighbour of conn.neighbours(config.snapRadius)) { |
| 1671 | if (neighbourIsInStack(neighbour)) continue; |
| 1672 | if (conn.isConnected() && neighbour.isConnected()) continue; |
| 1673 | |
| 1674 | if (conn.isSuperior()) { |
| 1675 | neighbour.bumpAwayFrom(conn, /* initiatedByThis = */ false); |
| 1676 | } else if (!neighbour.getSourceBlock().isDragging()) { |
| 1677 | conn.bumpAwayFrom(neighbour, /* initiatedByThis = */ true); |
| 1678 | } |
| 1679 | } |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | /** |
| 1684 | * Snap to grid, and then bump neighbouring blocks away at the end of the next |
no test coverage detected