From 96e8fc794ed8c52f4bcfaa5643dcef185337bed9 Mon Sep 17 00:00:00 2001 From: Monica Kozbial Date: Fri, 18 Sep 2020 16:08:39 -0700 Subject: [PATCH] Don't render children of collapsed blocks (#4264) * Partially revert collapsed block changes and add additional handling for setting children of collapsed blocks to not rendered * Improve performance by checking if child is rendered in updateDisabled --- core/block_svg.js | 16 +++++++++++++--- core/input.js | 3 +++ core/rendered_connection.js | 8 ++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/core/block_svg.js b/core/block_svg.js index 929f7d0bb..19ee4bf9b 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -87,7 +87,6 @@ Blockly.BlockSvg = function(workspace, prototypeName, opt_id) { */ this.renderIsInProgress_ = false; - /** @type {!Blockly.WorkspaceSvg} */ this.workspace = workspace; @@ -643,14 +642,21 @@ Blockly.BlockSvg.prototype.updateCollapsed_ = function() { var collapsedInputName = Blockly.Block.COLLAPSED_INPUT_NAME; var collapsedFieldName = Blockly.Block.COLLAPSED_FIELD_NAME; + var renderList = []; + // Show/hide the inputs. for (var i = 0, input; (input = this.inputList[i]); i++) { if (input.name != collapsedInputName) { - input.setVisible(!collapsed); + renderList.push.apply(renderList, input.setVisible(!collapsed)); } } if (!collapsed) { this.removeInput(collapsedInputName); + if (this.rendered) { + for (var i = 0, block; (block = renderList[i]); i++) { + block.render(); + } + } return; } @@ -975,7 +981,9 @@ Blockly.BlockSvg.prototype.updateDisabled = function() { var children = this.getChildren(false); this.applyColour(); for (var i = 0, child; (child = children[i]); i++) { - child.updateDisabled(); + if (child.rendered) { + child.updateDisabled(); + } } }; @@ -1626,10 +1634,12 @@ Blockly.BlockSvg.prototype.render = function(opt_bubble) { if (this.isCollapsed()) { this.updateCollapsed_(); } + this.workspace.getRenderer().render(this); this.updateConnectionLocations_(); if (opt_bubble !== false) { + // Render all blocks above this one (propogate a reflow). var parentBlock = this.getParent(); if (parentBlock) { parentBlock.render(true); diff --git a/core/input.js b/core/input.js index 40a454e31..b8b95e846 100644 --- a/core/input.js +++ b/core/input.js @@ -200,6 +200,9 @@ Blockly.Input.prototype.setVisible = function(visible) { } var child = this.connection.targetBlock(); if (child) { + if (!visible) { + child.rendered = false; + } child.getSvgRoot().style.display = visible ? 'block' : 'none'; } } diff --git a/core/rendered_connection.js b/core/rendered_connection.js index 5188d5504..b16cc1a00 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -459,6 +459,11 @@ Blockly.RenderedConnection.prototype.onFailedConnect = function( */ Blockly.RenderedConnection.prototype.disconnectInternal_ = function(parentBlock, childBlock) { + // The input the child block was connected to (if any). + var parentInput = parentBlock.getInputWithBlock(childBlock); + if (parentInput && !parentInput.isVisible()) { + childBlock.rendered = true; + } Blockly.RenderedConnection.superClass_.disconnectInternal_.call(this, parentBlock, childBlock); // Rerender the parent so that it may reflow. @@ -544,6 +549,9 @@ Blockly.RenderedConnection.prototype.connect_ = function(childConnection) { var parentInput = parentBlock.getInputWithBlock(childBlock); if (parentInput) { var visible = parentInput.isVisible(); + if (!visible) { + childBlock.rendered = false; + } childBlock.getSvgRoot().style.display = visible ? 'block' : 'none'; } };