mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
Correctly update variable list when pasting code
This commit is contained in:
parent
97801a0e2f
commit
dfe61087f0
2 changed files with 12 additions and 6 deletions
|
@ -202,15 +202,18 @@ Blockly.Workspace.prototype.clear = function() {
|
|||
/**
|
||||
* Walk the workspace and update the list of variables to only contain ones in
|
||||
* use on the workspace. Use when loading new workspaces from disk.
|
||||
* @param {boolean} clearList True if the old variable list should be cleared.
|
||||
*/
|
||||
Blockly.Workspace.prototype.updateVariableList = function() {
|
||||
Blockly.Workspace.prototype.updateVariableList = function(clearList) {
|
||||
// TODO: Sort
|
||||
if (!this.isFlyout) {
|
||||
// Update the list in place so that the flyout's references stay correct.
|
||||
this.variableList.length = 0;
|
||||
var allVariables = Blockly.Variables.allVariables(this);
|
||||
if (clearList) {
|
||||
this.variableList.length = 0;
|
||||
}
|
||||
var allVariables = Blockly.Variables.allUsedVariables(this);
|
||||
for (var i = 0; i < allVariables.length; i++) {
|
||||
this.variableList.push(allVariables[i]);
|
||||
this.createVariable(allVariables[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -241,7 +244,10 @@ Blockly.Workspace.prototype.renameVariable = function(oldName, newName) {
|
|||
* @param {string} name The new variable's name.
|
||||
*/
|
||||
Blockly.Workspace.prototype.createVariable = function(name) {
|
||||
this.variableList.push(name);
|
||||
var index = this.variableList.indexOf(name);
|
||||
if (index == -1) {
|
||||
this.variableList.push(name);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -314,7 +314,7 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) {
|
|||
}
|
||||
Blockly.Field.stopCache();
|
||||
|
||||
workspace.updateVariableList();
|
||||
workspace.updateVariableList(false);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue