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

Method unplugFromStack

packages/blockly/core/block.ts:494–529  ·  view source on GitHub ↗

* Unplug this statement block from its superior block. Optionally reconnect * the block underneath with the block on top. * * @param opt_healStack Disconnect child statement and reconnect stack. * Defaults to false.

(opt_healStack?: boolean)

Source from the content-addressed store, hash-verified

492 * Defaults to false.
493 */
494 private unplugFromStack(opt_healStack?: boolean) {
495 let previousTarget = null;
496 if (this.previousConnection?.isConnected()) {
497 // Remember the connection that any next statements need to connect to.
498 previousTarget = this.previousConnection.targetConnection;
499 // Detach this block from the parent's tree.
500 this.previousConnection.disconnect();
501 }
502
503 if (!opt_healStack) return;
504
505 // Immovable or shadow next blocks need to move along with the block; keep
506 // going until we encounter a normal block or run off the end of the stack.
507 let nextBlock = this.getNextBlock();
508 while (nextBlock && (nextBlock.isShadow() || !nextBlock.isMovable())) {
509 nextBlock = nextBlock.getNextBlock();
510 }
511 if (!nextBlock) return;
512
513 // Disconnect the next statement.
514 const nextTarget =
515 nextBlock.previousConnection?.targetBlock()?.nextConnection
516 ?.targetConnection ?? null;
517 nextTarget?.disconnect();
518 if (
519 previousTarget &&
520 this.workspace.connectionChecker.canConnect(
521 previousTarget,
522 nextTarget,
523 false,
524 )
525 ) {
526 // Attach the next statement to the previous statement.
527 previousTarget.connect(nextTarget!);
528 }
529 }
530
531 /**
532 * Returns all connections originating from this block.

Callers 1

unplugMethod · 0.95

Calls 8

getNextBlockMethod · 0.95
isConnectedMethod · 0.80
disconnectMethod · 0.80
isShadowMethod · 0.80
connectMethod · 0.80
isMovableMethod · 0.65
canConnectMethod · 0.65
targetBlockMethod · 0.45

Tested by

no test coverage detected