diff --git a/core/block.js b/core/block.js index 5cd0bfff7..3adc9a479 100644 --- a/core/block.js +++ b/core/block.js @@ -1078,7 +1078,7 @@ Blockly.Block.prototype.updateVarName = function(variable) { for (var j = 0, field; field = input.fieldRow[j]; j++) { if (field.referencesVariables() && variable.getId() == field.getValue()) { - field.setText(variable.name); + field.updateVariableName(); } } } diff --git a/core/field.js b/core/field.js index 9120df0d7..c5bd528fb 100644 --- a/core/field.js +++ b/core/field.js @@ -706,6 +706,7 @@ Blockly.Field.prototype.getText = function() { /** * Set the text in this field. Trigger a rerender of the source block. * @param {*} newText New text. + * @deprecated 2019 setText should not be used directly. Use setValue instead. */ Blockly.Field.prototype.setText = function(newText) { if (newText === null) { diff --git a/core/field_image.js b/core/field_image.js index bd5a56ae1..ee7cb6628 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -167,8 +167,19 @@ Blockly.FieldImage.prototype.getFlipRtl = function() { * Set the alt text of this image. * @param {?string} alt New alt text. * @override + * @deprecated 2019 setText has been deprecated for all fields. Instead use + * setAlt to set the alt text of the field. */ Blockly.FieldImage.prototype.setText = function(alt) { + this.setAlt(alt); +}; + +/** + * Set the alt text of this image. + * @param {?string} alt New alt text. + * @public + */ +Blockly.FieldImage.prototype.setAlt = function(alt) { if (alt === null) { // No change if null. return; diff --git a/core/field_variable.js b/core/field_variable.js index 42fba9ebe..5e5761b39 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -253,7 +253,7 @@ Blockly.FieldVariable.prototype.doClassValidation_ = function(newId) { Blockly.FieldVariable.prototype.doValueUpdate_ = function(newId) { this.variable_ = Blockly.Variables.getVariable(this.workspace_, newId); this.value_ = newId; - this.text_ = (this.variable_.name); + this.text_ = this.variable_.name; this.isDirty_ = true; }; @@ -341,6 +341,16 @@ Blockly.FieldVariable.prototype.setTypes_ = function(opt_variableTypes, this.variableTypes = variableTypes; }; +/** + * A callback to update the name of a variable. Should only be called by + * the block. + * @package + */ +Blockly.FieldVariable.prototype.updateVariableName = function() { + this.text_ = this.variable_.name; + this.forceRerender(); +}; + /** * Return a sorted list of variable names for variable dropdown menus. * Include a special option at the end for creating a new variable name.