diff --git a/core/field.js b/core/field.js index 4060ac62b..5155877ef 100644 --- a/core/field.js +++ b/core/field.js @@ -462,6 +462,17 @@ Blockly.Field.prototype.setText = function(newText) { return; } this.text_ = newText; + this.forceRerender(); +}; + +/** + * Force a rerender of the block that this field is installed on, which will + * rerender this field and adjust for any sizing changes. + * Other fields on the same block will not rerender, because their sizes have + * already been recorded. + * @package + */ +Blockly.Field.prototype.forceRerender = function() { // Set width to 0 to force a rerender of this field. this.size_.width = 0; diff --git a/core/field_dropdown.js b/core/field_dropdown.js index e0321f2d3..5ceac3f42 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -413,17 +413,20 @@ Blockly.FieldDropdown.prototype.setValue = function(newValue) { var content = options[i][0]; if (typeof content == 'object') { this.imageJson_ = content; - this.setText(content.alt); + this.text_ = content.alt; } else { this.imageJson_ = null; - this.setText(content); + this.text_ = content; } + // Always rerender if either the value or the text has changed. + this.forceRerender(); return; } } // Value not found. Add it, maybe it will become valid once set // (like variable names). - this.setText(newValue); + this.text_ = newValue; + this.forceRerender(); }; /**