From 471f30111f6a10ce62a40adaa2562ef2661220bb Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 12 Aug 2024 10:19:52 -0700 Subject: [PATCH] fix: prevent deleting procedure definition blocks with references by dragging to the flyout --- src/scratch_dragger.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/scratch_dragger.js b/src/scratch_dragger.js index 66f4be8bc7..35a1fce299 100644 --- a/src/scratch_dragger.js +++ b/src/scratch_dragger.js @@ -10,6 +10,27 @@ class ScratchDragger extends Blockly.dragging.Dragger { setDraggable(draggable) { this.draggable = draggable; } + + onDragEnd(event) { + if ( + this.draggable instanceof Blockly.BlockSvg && + this.draggable.type === "procedures_definition" + ) { + const procCode = this.draggable + .getInputTargetBlock("custom_block") + .getProcCode(); + const hasCaller = this.workspace + .getBlocksByType("procedures_call") + .some((b) => b.getProcCode() === procCode); + if (hasCaller) { + Blockly.dialog.alert(Blockly.Msg.PROCEDURE_USED); + this.draggable.revertDrag(); + this.draggable.endDrag(); + return; + } + } + super.onDragEnd(event); + } } Blockly.registry.register(