From 8f601345bb004b99dcfeb782744de680bd064c6b Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 17 Jun 2016 12:39:18 -0700 Subject: [PATCH] cache delete areas instead of recalculating them onMouseDown --- core/block_svg.js | 1 - core/flyout.js | 4 ++++ core/toolbox.js | 4 ++++ core/trashcan.js | 4 ++++ core/workspace_svg.js | 3 +++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/core/block_svg.js b/core/block_svg.js index 8fc64f3a8..c1f2b8df6 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -535,7 +535,6 @@ Blockly.BlockSvg.prototype.onMouseDown_ = function(e) { Blockly.terminateDrag_(); this.select(); Blockly.hideChaff(); - this.workspace.recordDeleteAreas(); if (Blockly.isRightButton(e)) { // Right-click. this.showContextMenu_(e); diff --git a/core/flyout.js b/core/flyout.js index 66d5c2c6e..85aaee983 100644 --- a/core/flyout.js +++ b/core/flyout.js @@ -952,6 +952,10 @@ Blockly.Flyout.prototype.filterForCapacity_ = function() { * @return {goog.math.Rect} Rectangle in which to delete. */ Blockly.Flyout.prototype.getClientRect = function() { + if (!this.svgGroup_) { + return null; + } + var flyoutRect = this.svgGroup_.getBoundingClientRect(); // BIG_NUM is offscreen padding so that blocks dragged beyond the shown flyout // area are still deleted. Must be larger than the largest screen size, diff --git a/core/toolbox.js b/core/toolbox.js index d9ca56dcc..b5b27f869 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -390,6 +390,10 @@ Blockly.Toolbox.prototype.clearSelection = function() { * @return {goog.math.Rect} Rectangle in which to delete. */ Blockly.Toolbox.prototype.getClientRect = function() { + if (!this.HtmlDiv) { + return null; + } + // BIG_NUM is offscreen padding so that blocks dragged beyond the toolbox // area are still deleted. Must be smaller than Infinity, but larger than // the largest screen size. diff --git a/core/trashcan.js b/core/trashcan.js index 0a2954308..28baa0f20 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -265,6 +265,10 @@ Blockly.Trashcan.prototype.position = function() { * @return {goog.math.Rect} Rectangle in which to delete. */ Blockly.Trashcan.prototype.getClientRect = function() { + if (!this.svgGroup_) { + return null; + } + var trashRect = this.svgGroup_.getBoundingClientRect(); var left = trashRect.left + this.SPRITE_LEFT_ - this.MARGIN_HOTSPOT_; var top = trashRect.top + this.SPRITE_TOP_ - this.MARGIN_HOTSPOT_; diff --git a/core/workspace_svg.js b/core/workspace_svg.js index de636a7a2..95150df19 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -211,6 +211,7 @@ Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) { this.addFlyout_(); } this.updateGridPattern_(); + this.recordDeleteAreas(); return this.svgGroup_; }; @@ -355,6 +356,8 @@ Blockly.WorkspaceSvg.prototype.resize = function() { if (this.scrollbar) { this.scrollbar.resize(); } + + this.recordDeleteAreas(); }; /**