Fix events for variable fields on new blocks; fix tests

This commit is contained in:
Rachel Fenichel
2017-12-19 11:28:23 -08:00
parent 3e56e6f8f2
commit 6218750207
6 changed files with 299 additions and 171 deletions

View File

@@ -86,28 +86,31 @@ Blockly.Xml.blockToDomWithXY = function(block, opt_noId) {
return element;
};
/**
* 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) {
var id = field.getValue();
var variable = workspace.getVariableById(id);
// 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);
if (!variable) {
if (workspace.isFlyout && workspace.targetWorkspace) {
var potentialVariableMap = workspace.getPotentialVariableMap();
if (potentialVariableMap) {
variable = potentialVariableMap.getVariableById(id);
}
}
}
if (variable) {
var container = goog.dom.createDom('field', null, variable.name);
container.setAttribute('name', field.name);
container.setAttribute('id', variable.getId());
container.setAttribute('variabletype', variable.type);
return container;
} else {
// something went wrong?
console.warn('no variable in fieldtodom');
return null;
throw Error('Tried to serialize a variable field with no variable.');
}
var container = goog.dom.createDom('field', null, variable.name);
container.setAttribute('name', field.name);
container.setAttribute('id', variable.getId());
container.setAttribute('variabletype', variable.type);
return container;
};
/**