app/assets/htmls/gs-element-blockly.html in gobstones-blockly-0.29.0 vs app/assets/htmls/gs-element-blockly.html in gobstones-blockly-0.29.1
- old
+ new
@@ -3411,15 +3411,27 @@
xmlField.setAttribute('name', 'VAR');
var xmlBlock = goog.dom.createDom('block', null, xmlField);
xmlBlock.setAttribute('type', 'variables_get');
var callback = Blockly.ContextMenu.callbackFactory(procedureBlock, xmlBlock);
-
+
return function() {
var block = callback();
block.$parent = procedureBlock.id;
- block.moveBy(procedureBlock.width, -14);
+
+ try {
+ Blockly.Events.disabled_ = 1;
+ const posParent = procedureBlock.getRelativeToSurfaceXY();
+ const pos = block.getRelativeToSurfaceXY();
+ let width = procedureBlock.width;
+ const returnBlock = procedureBlock.inputList.find((it) => it.name === "RETURN");
+ if (returnBlock) width -= returnBlock.renderWidth - 8;
+
+ block.moveBy(posParent.x - pos.x + width + 16, posParent.y - pos.y + 6);
+ } finally {
+ Blockly.Events.disabled_ = 0;
+ }
};
};
var getAvailableName = function(self, name) {
var result = name;
@@ -3483,11 +3495,11 @@
if (oldName !== newName)
newName = getAvailableName(self, newName);
self.arguments_[i] = newName;
-
+
var blocks = self.workspace.getAllBlocks();
for (block of blocks) {
if (block.type === self.callType_ && block.getProcedureCall() === self.getProcedureDef()[0]) {
block.arguments_ = block.arguments_.map(function(it) {
return it === oldName ? newName : it;
@@ -3510,11 +3522,11 @@
.appendDummyInput(id)
.appendField(Blockly.Msg.PROCEDURES_BEFORE_PARAMS)
.appendField(nameField, 'ARG' + i)
.appendField(createCallButton)
.appendField(removeParameterButton);
-
+
self.moveInputBefore(id, 'STACK');
};
var makeProcedureDomToMutation = function() {
return function(xmlElement) {
@@ -3615,11 +3627,26 @@
xmlMutation.appendChild(xmlArg);
}
var xmlBlock = goog.dom.createDom('block', null, xmlMutation);
xmlBlock.setAttribute('type', self.callType_);
- Blockly.ContextMenu.callbackFactory(self, xmlBlock)();
+ const block = Blockly.ContextMenu.callbackFactory(self, xmlBlock)();
+
+ try {
+ const procedureBlock = self;
+
+ Blockly.Events.disabled_ = 1;
+ const posParent = procedureBlock.getRelativeToSurfaceXY();
+ const pos = block.getRelativeToSurfaceXY();
+ let width = procedureBlock.width;
+ const returnBlock = procedureBlock.inputList.find((it) => it.name === "RETURN");
+ if (returnBlock) width -= returnBlock.renderWidth - 8;
+
+ block.moveBy(posParent.x - pos.x + width + 16, posParent.y - pos.y + 6);
+ } finally {
+ Blockly.Events.disabled_ = 0;
+ }
}
);
input.appendField(createCallButton);
};
};
@@ -4173,10 +4200,19 @@
Blockly.CUSTOM_COLORS = {"globalHsvSaturation":0.45,"globalHsvValue":0.65,"primitiveCommand":"#1d3c99","assignation":"#051d66","controlStructure":"#0f2b80","literalExpression":"#1d992c","primitiveExpression":"#1d992c","operator":"#0f801c","program":"#8d1bb3","interactiveProgram":"#6e158c","interactiveBinding":"#a11fcc","procedure":"#935ba6","function":"#745380","primitiveProcedure":"#2e4fb3","primitiveFunction":"#2eb33e","procedure_call":"#355bcc","function_call":"#35cc47","variable":"#056610","parameter":"#056610","complete":"#ff0000","H":{"commands":225,"expressions":127,"definitions":285},"S":{"assignation":95,"variable":95,"parameter":95,"primitiveCommand":81,"literalExpression":81,"primitiveExpression":81,"controlStructure":88,"operator":88,"procedure_call":74,"function_call":74,"primitiveProcedure":74,"primitiveFunction":74,"program":85,"interactiveProgram":85,"interactiveBinding":85,"procedure":45,"function":35,"complete":99},"V":{"assignation":40,"variable":40,"parameter":40,"primitiveCommand":60,"literalExpression":60,"primitiveExpression":60,"controlStructure":50,"operator":50,"procedure_call":80,"function_call":80,"primitiveProcedure":70,"primitiveFunction":70,"program":70,"interactiveProgram":55,"interactiveBinding":80,"procedure":65,"function":50,"complete":99}};
Blockly.AVAILABLE_ICONS = ["bool-false.svg","bool-true.svg","clean.png","color-azul.svg","color-negro.svg","color-rojo.svg","color-verde.svg","direccion-este.svg","direccion-norte.svg","direccion-oeste.svg","direccion-sur.svg","hand.png","minus.png","plus.png"];
const EMPTY_GIF = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
+const ATOMICALLY = (action) => {
+ try {
+ Blockly.Events.disabled_ = 1;
+ action();
+ } finally {
+ Blockly.Events.disabled_ = 0;
+ }
+}
+
const getOptions = (block) => {
const parentWorkspace = block.workspace.options.parentWorkspace;
return parentWorkspace && parentWorkspace.options || block.workspace.options
}
const hasLocalMedia = (name) => Blockly.AVAILABLE_ICONS.includes(name)
@@ -4200,14 +4236,15 @@
};
const createVariable = (parent, name) => {
const workspace = parent.workspace;
Blockly.createBlockSvg(workspace, 'variables_get', b => {
- b.setFieldValue(name, 'VAR');
-
- const posParent = parent.getRelativeToSurfaceXY();
- const pos = b.getRelativeToSurfaceXY();
- b.moveBy(posParent.x - pos.x + parent.width + 16, posParent.y - pos.y + b.height + 6);
+ ATOMICALLY(() => {
+ b.setFieldValue(name, 'VAR');
+ const posParent = parent.getRelativeToSurfaceXY();
+ const pos = b.getRelativeToSurfaceXY();
+ b.moveBy(posParent.x - pos.x + parent.width + 16, posParent.y - pos.y + b.height + 6);
+ });
});
}
const triggerRefresh = (block) => {
getOptions(block).parentController.onBlocklyWorkspaceUpdate();
\ No newline at end of file