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.
This commit is contained in:
picklesrus
2016-06-17 14:33:23 -07:00
committed by Neil Fraser
parent cc9b490bf9
commit 567fe6a2e8

View File

@@ -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;