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

Method unplugFromRow

packages/blockly/core/block.ts:419–458  ·  view source on GitHub ↗

* Unplug this block's output from an input on another block. Optionally * reconnect the block's parent to the only child block, if possible. * * @param opt_healStack Disconnect right-side block and connect to left-side * block. Defaults to false.

(opt_healStack?: boolean)

Source from the content-addressed store, hash-verified

417 * block. Defaults to false.
418 */
419 private unplugFromRow(opt_healStack?: boolean) {
420 let parentConnection = null;
421 if (this.outputConnection?.isConnected()) {
422 parentConnection = this.outputConnection.targetConnection;
423 // Disconnect from any superior block.
424 this.outputConnection.disconnect();
425 }
426
427 // Return early in obvious cases.
428 if (!parentConnection || !opt_healStack) {
429 return;
430 }
431
432 const thisConnection = this.getOnlyValueConnection();
433 if (
434 !thisConnection ||
435 !thisConnection.isConnected() ||
436 thisConnection.targetBlock()!.isShadow()
437 ) {
438 // Too many or too few possible connections on this block, or there's
439 // nothing on the other side of this connection.
440 return;
441 }
442
443 const childConnection = thisConnection.targetConnection;
444 // Disconnect the child block.
445 childConnection?.disconnect();
446 // Connect child to the parent if possible, otherwise bump away.
447 if (
448 this.workspace.connectionChecker.canConnect(
449 childConnection,
450 parentConnection,
451 false,
452 )
453 ) {
454 parentConnection.connect(childConnection!);
455 } else {
456 childConnection?.onFailedConnect(parentConnection);
457 }
458 }
459
460 /**
461 * Returns the connection on the value input that is connected to another

Callers 1

unplugMethod · 0.95

Calls 8

isConnectedMethod · 0.80
disconnectMethod · 0.80
isShadowMethod · 0.80
connectMethod · 0.80
canConnectMethod · 0.65
targetBlockMethod · 0.45
onFailedConnectMethod · 0.45

Tested by

no test coverage detected