mirror of
https://github.com/google/blockly.git
synced 2026-01-11 19:07:08 +01:00
Make dropdowns update correctly when you switch between images. (#1321)
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user