mirror of
https://github.com/google/blockly.git
synced 2026-03-09 14:50:09 +01:00
Fix problem with clearing flyout after a variable was deleted.
This commit is contained in:
@@ -137,6 +137,18 @@ Blockly.FieldVariable.prototype.getText = function() {
|
||||
return this.variable_ ? this.variable_.name : '';
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the variable model for the selected variable.
|
||||
* Not guaranteed to be in the variable map on the workspace (e.g. if accessed
|
||||
* after the variable has been deleted).
|
||||
* @return {?Blockly.VariableModel} the selected variable, or null if none was
|
||||
* selected.
|
||||
* @package
|
||||
*/
|
||||
Blockly.FieldVariable.prototype.getVariable = function() {
|
||||
return this.variable_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the variable ID.
|
||||
* @param {string} id New variable ID, which must reference an existing
|
||||
|
||||
14
core/xml.js
14
core/xml.js
@@ -89,19 +89,20 @@ Blockly.Xml.blockToDomWithXY = function(block, opt_noId) {
|
||||
/**
|
||||
* Encode a variable field as XML.
|
||||
* @param {!Blockly.Field} field The field to encode.
|
||||
* @param {!Blockly.Workspace} workspace The workspace that the field is in.
|
||||
* @return {?Element} XML element, or null if the field did not need to be
|
||||
* serialized.
|
||||
* @private
|
||||
*/
|
||||
Blockly.Xml.fieldToDomVariable_ = function(field, workspace) {
|
||||
Blockly.Xml.fieldToDomVariable_ = function(field) {
|
||||
var id = field.getValue();
|
||||
// The field had not been initialized fully before being serialized.
|
||||
if (id == null) {
|
||||
field.initModel();
|
||||
id = field.getValue();
|
||||
}
|
||||
var variable = Blockly.Variables.getVariable(workspace, id);
|
||||
// Get the variable directly from the field, instead of doing a lookup. This
|
||||
// will work even if the variable has already been deleted.
|
||||
var variable = field.getVariable();
|
||||
|
||||
if (!variable) {
|
||||
throw Error('Tried to serialize a variable field with no variable.');
|
||||
@@ -121,10 +122,10 @@ Blockly.Xml.fieldToDomVariable_ = function(field, workspace) {
|
||||
* serialized.
|
||||
* @private
|
||||
*/
|
||||
Blockly.Xml.fieldToDom_ = function(field, workspace) {
|
||||
Blockly.Xml.fieldToDom_ = function(field) {
|
||||
if (field.name && field.EDITABLE) {
|
||||
if (field instanceof Blockly.FieldVariable) {
|
||||
return Blockly.Xml.fieldToDomVariable_(field, workspace);
|
||||
return Blockly.Xml.fieldToDomVariable_(field);
|
||||
} else {
|
||||
var container = goog.dom.createDom('field', null, field.getValue());
|
||||
container.setAttribute('name', field.name);
|
||||
@@ -143,10 +144,9 @@ Blockly.Xml.fieldToDom_ = function(field, workspace) {
|
||||
* @private
|
||||
*/
|
||||
Blockly.Xml.allFieldsToDom_ = function(block, element) {
|
||||
var workspace = block.workspace;
|
||||
for (var i = 0, input; input = block.inputList[i]; i++) {
|
||||
for (var j = 0, field; field = input.fieldRow[j]; j++) {
|
||||
var fieldDom = Blockly.Xml.fieldToDom_(field, workspace);
|
||||
var fieldDom = Blockly.Xml.fieldToDom_(field);
|
||||
if (fieldDom) {
|
||||
element.appendChild(fieldDom);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user