Make dropdowns update correctly when you switch between images. (#1321)

This commit is contained in:
Rachel Fenichel
2017-09-18 13:09:07 -07:00
committed by GitHub
parent d4c21cea3a
commit dd50dde23d
2 changed files with 17 additions and 3 deletions

View File

@@ -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;

View File

@@ -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();
};
/**