MCPcopy
hub / github.com/RaspberryPiFoundation/blockly / bumpNeighbours

Method bumpNeighbours

packages/blockly/core/block_svg.ts:1649–1681  ·  view source on GitHub ↗

* 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.

()

Source from the content-addressed store, hash-verified

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

Callers 1

scheduleSnapAndBumpMethod · 0.95

Calls 10

isDraggingMethod · 0.95
getConnections_Method · 0.95
getRootBlockMethod · 0.80
isSuperiorMethod · 0.80
isConnectedMethod · 0.80
bumpAwayFromMethod · 0.80
isDeadOrDyingMethod · 0.45
targetBlockMethod · 0.45
neighboursMethod · 0.45
getSourceBlockMethod · 0.45

Tested by

no test coverage detected