diff --git a/src/engine/target.js b/src/engine/target.js index 9388937df..461eb81f1 100644 --- a/src/engine/target.js +++ b/src/engine/target.js @@ -515,7 +515,7 @@ class Target extends EventEmitter { // for all references for a given ID instead of doing the below..? this.blocks.getAllVariableAndListReferences()[idToBeMerged]; - VariableUtil.mergeVariables(idToBeMerged, idToMergeWith, referencesToChange, optNewName); + VariableUtil.updateVariableIdentifiers(referencesToChange, idToMergeWith, optNewName); } /** diff --git a/src/serialization/sb3.js b/src/serialization/sb3.js index ed2b59973..ccc5dfb09 100644 --- a/src/serialization/sb3.js +++ b/src/serialization/sb3.js @@ -1160,7 +1160,7 @@ const replaceUnsafeCharsInVariableIds = function (targets) { // We're calling this on the stage target because we need a // target to call on but this shouldn't matter because we're passing // in all the varRefs we want to operate on - VariableUtil.mergeVariables(id, newId, allVarRefs); + VariableUtil.updateVariableIdentifiers(allVarRefs[id], newId); } return targets; }; diff --git a/src/util/variable-util.js b/src/util/variable-util.js index 80b59a4a7..c1dab8f8e 100644 --- a/src/util/variable-util.js +++ b/src/util/variable-util.js @@ -25,18 +25,17 @@ class VariableUtil { } /** - * Merge variable references with another variable. - * @param {string} idToBeMerged ID of the variable whose references need to be updated - * @param {string} idToMergeWith ID of the variable that the old references should be replaced with + * Give all variable references provided a new id and possibly new name. * @param {Array} referencesToUpdate Context of the change, the object containing variable * references to update. + * @param {string} newId ID of the variable that the old references should be replaced with * @param {?string} optNewName New variable name to merge with. The old * variable name in the references being updated should be replaced with this new name. * If this parameter is not provided or is '', no name change occurs. */ - static mergeVariables (idToBeMerged, idToMergeWith, referencesToUpdate, optNewName) { + static updateVariableIdentifiers (referencesToUpdate, newId, optNewName) { referencesToUpdate.map(ref => { - ref.referencingField.id = idToMergeWith; + ref.referencingField.id = newId; if (optNewName) { ref.referencingField.value = optNewName; }