Skip to content

Commit 71958b4

Browse files
committed
Adjusting behavior of getter blocks
1 parent dd06b0b commit 71958b4

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "proceds-blockly",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"homepage": "https://github.com/Program-AR/proceds-blockly",
55
"authors": [
66
"Alf Sanzo <[email protected]>"

proceds-blockly.js

+32-5
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,23 @@ window.initProcedsBlockly = function(customStatementType, initialize = () => {})
101101
xmlBlock.setAttribute('type', 'variables_get');
102102

103103
var callback = Blockly.ContextMenu.callbackFactory(procedureBlock, xmlBlock);
104-
104+
105105
return function() {
106106
var block = callback();
107107
block.$parent = procedureBlock.id;
108-
block.moveBy(procedureBlock.width, -14);
108+
109+
try {
110+
Blockly.Events.disabled_ = 1;
111+
const posParent = procedureBlock.getRelativeToSurfaceXY();
112+
const pos = block.getRelativeToSurfaceXY();
113+
let width = procedureBlock.width;
114+
const returnBlock = procedureBlock.inputList.find((it) => it.name === "RETURN");
115+
if (returnBlock) width -= returnBlock.renderWidth - 8;
116+
117+
block.moveBy(posParent.x - pos.x + width + 16, posParent.y - pos.y + 6);
118+
} finally {
119+
Blockly.Events.disabled_ = 0;
120+
}
109121
};
110122
};
111123

@@ -173,7 +185,7 @@ window.initProcedsBlockly = function(customStatementType, initialize = () => {})
173185
newName = getAvailableName(self, newName);
174186

175187
self.arguments_[i] = newName;
176-
188+
177189
var blocks = self.workspace.getAllBlocks();
178190
for (block of blocks) {
179191
if (block.type === self.callType_ && block.getProcedureCall() === self.getProcedureDef()[0]) {
@@ -200,7 +212,7 @@ window.initProcedsBlockly = function(customStatementType, initialize = () => {})
200212
.appendField(nameField, 'ARG' + i)
201213
.appendField(createCallButton)
202214
.appendField(removeParameterButton);
203-
215+
204216
self.moveInputBefore(id, 'STACK');
205217
};
206218

@@ -305,7 +317,22 @@ window.initProcedsBlockly = function(customStatementType, initialize = () => {})
305317
var xmlBlock = goog.dom.createDom('block', null, xmlMutation);
306318
xmlBlock.setAttribute('type', self.callType_);
307319

308-
Blockly.ContextMenu.callbackFactory(self, xmlBlock)();
320+
const block = Blockly.ContextMenu.callbackFactory(self, xmlBlock)();
321+
322+
try {
323+
const procedureBlock = self;
324+
325+
Blockly.Events.disabled_ = 1;
326+
const posParent = procedureBlock.getRelativeToSurfaceXY();
327+
const pos = block.getRelativeToSurfaceXY();
328+
let width = procedureBlock.width;
329+
const returnBlock = procedureBlock.inputList.find((it) => it.name === "RETURN");
330+
if (returnBlock) width -= returnBlock.renderWidth - 8;
331+
332+
block.moveBy(posParent.x - pos.x + width + 16, posParent.y - pos.y + 6);
333+
} finally {
334+
Blockly.Events.disabled_ = 0;
335+
}
309336
}
310337
);
311338
input.appendField(createCallButton);

0 commit comments

Comments
 (0)