Skip to content

Commit 453ffa9

Browse files
authored
fix: prevent dragging blocks into the slot occupied by the procedure definition block's example caller block (#118)
* fix: prevent replacing the procedure definition block's example caller block * chore: remove errant logging
1 parent 4b74d5c commit 453ffa9

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { ScratchContinuousToolbox } from "./scratch_continuous_toolbox.js";
3838
import "./scratch_continuous_category.js";
3939
import "./scratch_comment_icon.js";
4040
import "./scratch_variable_model.js";
41+
import "./scratch_connection_checker.js";
4142
import "./events_block_comment_change.js";
4243
import "./events_block_comment_collapse.js";
4344
import "./events_block_comment_create.js";

src/scratch_connection_checker.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @license
3+
* Copyright 2024 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import * as Blockly from "blockly/core";
8+
9+
class ScratchConnectionChecker extends Blockly.ConnectionChecker {
10+
// This check prevents dragging a block into the slot occupied by the
11+
// procedure caller example block in a procedure definition block.
12+
doDragChecks(a, b, distance) {
13+
if (
14+
b.getSourceBlock().type === "procedures_definition" &&
15+
b.getParentInput()?.name === "custom_block"
16+
) {
17+
return false;
18+
}
19+
20+
return super.doDragChecks(a, b, distance);
21+
}
22+
}
23+
24+
Blockly.registry.register(
25+
Blockly.registry.Type.CONNECTION_CHECKER,
26+
Blockly.registry.DEFAULT,
27+
ScratchConnectionChecker,
28+
true
29+
);

0 commit comments

Comments
 (0)