Skip to content

Commit

Permalink
fix: prevent deleting procedure definition blocks with references by …
Browse files Browse the repository at this point in the history
…dragging to the flyout (#120)
  • Loading branch information
gonfunko authored Aug 12, 2024
1 parent 0ca0620 commit fa9367d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/scratch_dragger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit fa9367d

Please sign in to comment.