From 567fe6a2e8702094879db79bf65a5d980186c6b3 Mon Sep 17 00:00:00 2001 From: picklesrus Date: Fri, 17 Jun 2016 14:33:23 -0700 Subject: [PATCH] Call svgResizeContents from block_svg's dipose so that deleting blocks (#434) from the context menu (or anywhere really) causes the workspace to recalculate its size. Remove the call to svgResizeContents from onMouseUp's logic for determining whether the block is being dropped in the trash since it calls dispose. One side effect of this is that when you delete multiple blocks resize gets called for each of them and the scrollbars move during the operation. This is most obviously seen by doing an airstrike in the playground and then deleting all the blocks at once. --- core/block_svg.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/core/block_svg.js b/core/block_svg.js index 8fc64f3a8..6a0df6f56 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -610,14 +610,7 @@ Blockly.BlockSvg.prototype.onMouseUp_ = function(e) { if (trashcan) { goog.Timer.callOnce(trashcan.close, 100, trashcan); } - // Save the block's workspace temporarily so we can resize the - // contents once the block is disposed. - var selectedWorkspace = Blockly.selected.workspace; Blockly.selected.dispose(false, true); - // Dropping a block on the trash can will usually cause the workspace to - // resize to contain the newly positioned block. Force a second resize - // now that the block has been deleted. - Blockly.resizeSvgContents(selectedWorkspace); } if (Blockly.highlightedConnection_) { Blockly.highlightedConnection_.unhighlight(); @@ -986,6 +979,9 @@ Blockly.BlockSvg.prototype.getSvgRoot = function() { Blockly.BlockSvg.prototype.dispose = function(healStack, animate) { Blockly.Tooltip.hide(); Blockly.Field.startCache(); + // Save the block's workspace temporarily so we can resize the + // contents once the block is disposed. + var blockWorkspace = this.workspace; // If this block is being dragged, unlink the mouse events. if (Blockly.selected == this) { this.unselect(); @@ -1012,6 +1008,7 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) { Blockly.BlockSvg.superClass_.dispose.call(this, healStack); goog.dom.removeNode(this.svgGroup_); + Blockly.resizeSvgContents(blockWorkspace); // Sever JavaScript to DOM connections. this.svgGroup_ = null; this.svgPath_ = null;