Make unique variable names in the flyout

This commit is contained in:
Rachel Fenichel
2017-12-04 15:46:44 -08:00
parent 523a10413b
commit 3ae7ac1cd4
2 changed files with 12 additions and 1 deletions

View File

@@ -63,6 +63,7 @@ Blockly.FieldVariable.getOrCreateVariable = function(workspace, text, type,
id) {
var potentialVariableMap = workspace.isFlyout ?
workspace.targetWorkspace.potentialVariableMap_ : null;
if (id) {
var variable = workspace.getVariableById(id);
if (!variable && potentialVariableMap) {
@@ -76,6 +77,12 @@ Blockly.FieldVariable.getOrCreateVariable = function(workspace, text, type,
}
// Didn't find the variable.
if (!variable) {
if (!text) {
var ws = workspace.isFlyout ? workspace.targetWorkspace : workspace;
// Variables without names get uniquely named for this workspace.
text = Blockly.Variables.generateUniqueName(ws);
}
if (potentialVariableMap) {
variable = potentialVariableMap.createVariable(text, type, id);
} else {
@@ -126,7 +133,7 @@ Blockly.FieldVariable.prototype.initModel = function() {
}
this.workspace_ = this.sourceBlock_.workspace;
var variable = Blockly.FieldVariable.getOrCreateVariable(
this.workspace_, this.defaultVariableName, this.defaultType_, null);
this.workspace_, name, this.defaultType_, null);
this.setValue(variable.getId());
};

View File

@@ -415,6 +415,7 @@ Blockly.Flyout.prototype.hide = function() {
this.workspace_.removeChangeListener(this.reflowWrapper_);
this.reflowWrapper_ = null;
}
// Do NOT delete the blocks here. Wait until Flyout.show.
// https://neil.fraser.name/news/2014/08/09/
};
@@ -542,6 +543,9 @@ Blockly.Flyout.prototype.clearOldBlocks_ = function() {
button.dispose();
}
this.buttons_.length = 0;
// Clear potential variables from the previous showing.
this.targetWorkspace_.potentialVariableMap_.clear();
};
/**