From 78e2fb2f4b8b0f9b2874d34c8a528eb91cdc34d0 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Wed, 11 Dec 2019 14:10:38 -0800 Subject: [PATCH] Fixed adding a variable field programmatically when it has a following field. (#3468) * Fixed adding a var field through mutator error. --- core/field_variable.js | 7 ++----- core/mutator.js | 10 +--------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/core/field_variable.js b/core/field_variable.js index 850e2c378..336c84a02 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -147,11 +147,8 @@ Blockly.FieldVariable.prototype.initModel = function() { this.sourceBlock_.workspace, null, this.defaultVariableName, this.defaultType_); - // Don't fire a change event for this setValue. It would have null as the - // old value, which is not valid. - Blockly.Events.disable(); - this.setValue(variable.getId()); - Blockly.Events.enable(); + // Don't call setValue because we don't want to cause a rerender. + this.doValueUpdate_(variable.getId()); }; /** diff --git a/core/mutator.js b/core/mutator.js index decb81f3a..c864c9f8d 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -372,15 +372,10 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { var block = this.block_; var oldMutationDom = block.mutationToDom(); var oldMutation = oldMutationDom && Blockly.Xml.domToText(oldMutationDom); - // Switch off rendering while the source block is rebuilt. - var savedRendered = block.rendered; - block.rendered = false; // Allow the source block to rebuild itself. block.compose(this.rootBlock_); - // Restore rendering and show the changes. - block.rendered = savedRendered; - // Mutation may have added some elements that need initializing. block.initSvg(); + block.render(); var newMutationDom = block.mutationToDom(); var newMutation = newMutationDom && Blockly.Xml.domToText(newMutationDom); if (oldMutation != newMutation) { @@ -394,9 +389,6 @@ Blockly.Mutator.prototype.workspaceChanged_ = function(e) { Blockly.Events.setGroup(false); }, Blockly.BUMP_DELAY); } - if (block.rendered) { - block.render(); - } if (oldMutation != newMutation && this.workspace_.keyboardAccessibilityMode) {