Fix renaming

This commit is contained in:
Rachel Fenichel
2017-11-30 17:12:39 -08:00
parent 86e88aae92
commit 112fcccb31
4 changed files with 42 additions and 43 deletions

View File

@@ -724,6 +724,24 @@ Blockly.Block.prototype.renameVar = function(oldName, newName) {
}
};
/**
* Notification that a variable is renaming.
* If the name matches one of this block's variables, rename it.
* @param {string} oldId ID of variable to rename.
* @param {string} newId ID of new variable. May be the same as oldId, but with
* an updated name.
*/
Blockly.Block.prototype.renameVarById = function(oldId, newId) {
for (var i = 0, input; input = this.inputList[i]; i++) {
for (var j = 0, field; field = input.fieldRow[j]; j++) {
if (field instanceof Blockly.FieldVariable &&
oldId == field.getValue()) {
field.setValue(newId);
}
}
}
};
/**
* Returns the language-neutral value from the field of a block.
* @param {string} name The name of the field.