mirror of
https://github.com/google/blockly.git
synced 2026-01-09 10:00:09 +01:00
Make unique variable names in the flyout
This commit is contained in:
@@ -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());
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user