Merge pull request #1520 from rachel-fenichel/feature/variables_headless

Fix headless
This commit is contained in:
Rachel Fenichel
2017-12-19 16:53:51 -08:00
committed by GitHub
2 changed files with 23 additions and 3 deletions

View File

@@ -271,6 +271,23 @@ Blockly.Block.prototype.dispose = function(healStack) {
}
};
/**
* Call initModel on all fields on the block.
* May be called more than once.
* Either initModel or initSvg must be called after creating a block and before
* first interaction with it.
* @public
*/
Blockly.Block.prototype.initModel = function() {
for (var i = 0, input; input = this.inputList[i]; i++) {
for (var j = 0, field; field = input.fieldRow[j]; j++) {
if (field.initModel) {
field.initModel();
}
}
}
};
/**
* Unplug this block from its superior block. If this block is a statement,
* optionally reconnect the block underneath with the block on top.

View File

@@ -502,12 +502,11 @@ Blockly.Xml.domToBlock = function(xmlBlock, workspace) {
var variablesBeforeCreation = workspace.getAllVariables();
try {
var topBlock = Blockly.Xml.domToBlockHeadless_(xmlBlock, workspace);
// Generate list of all blocks.
var blocks = topBlock.getDescendants();
if (workspace.rendered) {
// TODO (fenichel): Otherwise call initModel?
// Hide connections to speed up assembly.
topBlock.setConnectionsHidden(true);
// Generate list of all blocks.
var blocks = topBlock.getDescendants();
// Render each block.
for (var i = blocks.length - 1; i >= 0; i--) {
blocks[i].initSvg();
@@ -526,6 +525,10 @@ Blockly.Xml.domToBlock = function(xmlBlock, workspace) {
// Allow the scrollbars to resize and move based on the new contents.
// TODO(@picklesrus): #387. Remove when domToBlock avoids resizing.
workspace.resizeContents();
} else {
for (var i = blocks.length - 1; i >= 0; i--) {
blocks[i].initModel();
}
}
} finally {
Blockly.Events.enable();