From 08720929d35ea13ee0b377e28ebf1039b313cfd7 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Mon, 19 Aug 2019 10:53:00 -0700 Subject: [PATCH] Changed setConnectionsHidden to waitToTrackConnections and startTrackingConnections. --- core/block_svg.js | 75 +++++++++++++++++++++++++++++------------------ core/xml.js | 8 ++--- 2 files changed, 51 insertions(+), 32 deletions(-) diff --git a/core/block_svg.js b/core/block_svg.js index b04f5eccb..f2004b684 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -141,6 +141,7 @@ Blockly.utils.object.inherits(Blockly.BlockSvg, Blockly.Block); * Height is in workspace units. */ Blockly.BlockSvg.prototype.height = 0; + /** * Width of this block, including any connected value blocks. * Width is in workspace units. @@ -162,6 +163,15 @@ Blockly.BlockSvg.prototype.dragStartXY_ = null; */ Blockly.BlockSvg.prototype.warningTextDb_ = null; +/** + * Should the block tell its connections to start tracking inside the render + * method? Or it should it wait for startTrackingConnections to be called + * separately? + * @type {boolean} + * @private + */ +Blockly.BlockSvg.prototype.waitToTrackConnections_ = false; + /** * Constant for identifying rows that are to be rendered inline. * Don't collide with Blockly.INPUT_VALUE and friends. @@ -1437,35 +1447,41 @@ Blockly.BlockSvg.prototype.appendInput_ = function(type, name) { return input; }; -/** - * Set whether the connections are hidden (not tracked in a database) or not. - * Recursively walk down all child blocks (except collapsed blocks). - * @param {boolean} hidden True if connections are hidden. - * @package - */ -Blockly.BlockSvg.prototype.setConnectionsHidden = function(hidden) { - if (!hidden && this.isCollapsed()) { - if (this.outputConnection) { - this.outputConnection.setHidden(hidden); +Blockly.BlockSvg.prototype.waitToTrackConnections = function() { + this.waitToTrackConnections_ = true; + var children = this.getChildren(); + for (var i = 0, child; child = children[i]; i++) { + child.waitToTrackConnections(); + } +}; + +Blockly.BlockSvg.prototype.startTrackingConnections = function() { + if (this.previousConnection) { + this.previousConnection.setHidden(false); + } + if (this.outputConnection) { + this.outputConnection.setHidden(false); + } + if (this.nextConnection) { + this.nextConnection.setHidden(false); + var child = this.nextConnection.targetBlock(); + if (child) { + child.startTrackingConnections(); } - if (this.previousConnection) { - this.previousConnection.setHidden(hidden); - } - if (this.nextConnection) { - this.nextConnection.setHidden(hidden); - var child = this.nextConnection.targetBlock(); - if (child) { - child.setConnectionsHidden(hidden); - } - } - } else { - var myConnections = this.getConnections_(true); - for (var i = 0, connection; connection = myConnections[i]; i++) { - connection.setHidden(hidden); - if (connection.isSuperior()) { - var child = connection.targetBlock(); - if (child) { - child.setConnectionsHidden(hidden); + } + + // If we're collapsed we want the invisible inputs' connections + // to remain untracked. + if (!this.collapsed_) { + for (var i = 0; i < this.inputList.length; i++) { + var conn = this.inputList[i].connection; + if (conn) { + conn.setHidden(false); + + // Pass tracking on down the chain. + var block = conn.targetBlock(); + if (block) { + block.startTrackingConnections(); } } } @@ -1616,6 +1632,9 @@ Blockly.BlockSvg.prototype.render = function(opt_bubble) { (/** @type {!Blockly.WorkspaceSvg} */ (this.workspace)).getRenderer().render(this); // No matter how we rendered, connection locations should now be correct. this.updateConnectionLocations_(); + if (!this.waitToTrackConnections_) { + this.startTrackingConnections(); + } if (opt_bubble !== false) { // Render all blocks above this one (propagate a reflow). var parentBlock = this.getParent(); diff --git a/core/xml.js b/core/xml.js index f152f0a0f..6f6478267 100644 --- a/core/xml.js +++ b/core/xml.js @@ -550,8 +550,8 @@ Blockly.Xml.domToBlock = function(xmlBlock, workspace) { // Generate list of all blocks. var blocks = topBlock.getDescendants(false); if (workspace.rendered) { - // Hide connections to speed up assembly. - topBlock.setConnectionsHidden(true); + // Wait to track connections to speed up assembly. + topBlock.waitToTrackConnections(); // Render each block. for (var i = blocks.length - 1; i >= 0; i--) { blocks[i].initSvg(); @@ -562,8 +562,8 @@ Blockly.Xml.domToBlock = function(xmlBlock, workspace) { // Populating the connection database may be deferred until after the // blocks have rendered. setTimeout(function() { - if (topBlock.workspace) { // Check that the block hasn't been deleted. - topBlock.setConnectionsHidden(false); + if (!topBlock.disposed) { // Check that the block hasn't been deleted. + topBlock.startTrackingConnections(); } }, 1); topBlock.updateDisabled();