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

Method snapToGrid

packages/blockly/core/block_svg.ts:461–472  ·  view source on GitHub ↗

Snap this block to the nearest grid point.

()

Source from the content-addressed store, hash-verified

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

Callers 2

scheduleSnapAndBumpMethod · 0.95
cleanUpMethod · 0.45

Calls 7

moveToMethod · 0.95
getGridMethod · 0.80
shouldSnapMethod · 0.80
alignXYMethod · 0.80
getParentMethod · 0.65
isDeadOrDyingMethod · 0.45

Tested by

no test coverage detected