Skip to content

Commit aa214d5

Browse files
authored
field_expandable_add.js -- global util code
1 parent 1138f47 commit aa214d5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

core/field_expandable_add.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,31 @@ Blockly.FieldExpandableAdd.prototype.init = function() {
101101
this.boxGroup_
102102
);
103103
this.fieldGroup_.insertBefore(this.boxGroup_, this.textElement_);
104+
105+
// since this field is typicall paired with expandable_remove, no need to paste this twice
106+
// inject utility code to source block
107+
this.sourceBlock_.fillInBlock = function (connection, type, optValue) {
108+
const srcBlock = this.sourceBlock_;
109+
if (connection.sourceBlock_.isInsertionMarker_) return;
110+
111+
Blockly.Events.disable();
112+
const block = srcBlock.workspace.newBlock(type);
113+
try {
114+
if (optValue) block.setFieldValue(optValue);
115+
block.setShadow(true);
116+
if (!srcBlock.isInsertionMarker()) {
117+
block.initSvg();
118+
block.render(false);
119+
}
120+
} finally {
121+
Blockly.Events.enable();
122+
}
123+
124+
if (Blockly.Events.isEnabled()) Blockly.Events.fire(new Blockly.Events.BlockCreate(block));
125+
if (block.outputConnection) block.outputConnection.connect(connection);
126+
else block.previousConnection.connect(connection);
127+
return block;
128+
}
104129
};
105130

106131
/**

0 commit comments

Comments
 (0)