Skip to content

Commit

Permalink
fix: prevent dragging blocks into the slot occupied by the procedure …
Browse files Browse the repository at this point in the history
…definition block's example caller block (scratchfoundation#118)

* fix: prevent replacing the procedure definition block's example caller block

* chore: remove errant logging
  • Loading branch information
gonfunko authored Aug 9, 2024
1 parent 4b74d5c commit 453ffa9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { ScratchContinuousToolbox } from "./scratch_continuous_toolbox.js";
import "./scratch_continuous_category.js";
import "./scratch_comment_icon.js";
import "./scratch_variable_model.js";
import "./scratch_connection_checker.js";
import "./events_block_comment_change.js";
import "./events_block_comment_collapse.js";
import "./events_block_comment_create.js";
Expand Down
29 changes: 29 additions & 0 deletions src/scratch_connection_checker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @license
* Copyright 2024 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import * as Blockly from "blockly/core";

class ScratchConnectionChecker extends Blockly.ConnectionChecker {
// This check prevents dragging a block into the slot occupied by the
// procedure caller example block in a procedure definition block.
doDragChecks(a, b, distance) {
if (
b.getSourceBlock().type === "procedures_definition" &&
b.getParentInput()?.name === "custom_block"
) {
return false;
}

return super.doDragChecks(a, b, distance);
}
}

Blockly.registry.register(
Blockly.registry.Type.CONNECTION_CHECKER,
Blockly.registry.DEFAULT,
ScratchConnectionChecker,
true
);

0 comments on commit 453ffa9

Please sign in to comment.