From c43988873ee4660d85cc1790ae8623c0187837ff Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Thu, 28 Feb 2019 17:09:30 -0800 Subject: [PATCH] Don't try to bump if the object has already been deleted. --- core/inject.js | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/core/inject.js b/core/inject.js index b4a1e3539..78593ff17 100644 --- a/core/inject.js +++ b/core/inject.js @@ -299,32 +299,33 @@ Blockly.createMainWorkspace_ = function(svg, options, blockDragSurface, var object = mainWorkspace.getCommentById(e.commentId); break; } - var objectMetrics = object.getBoundingRectangle(); + if (object) { + var objectMetrics = object.getBoundingRectangle(); - // Bump any object that's above the top back inside. - var overflowTop = metrics.viewTop - objectMetrics.topLeft.y; - if (overflowTop > 0) { - object.moveBy(0, overflowTop); + // Bump any object that's above the top back inside. + var overflowTop = metrics.viewTop - objectMetrics.topLeft.y; + if (overflowTop > 0) { + object.moveBy(0, overflowTop); + } + + // Bump any object that's below the bottom back inside. + var overflowBottom = metrics.viewBottom - objectMetrics.bottomRight.y; + if (overflowBottom < 0) { + object.moveBy(0, overflowBottom); + } + + // Bump any object that's off the left back inside. + var overflowLeft = metrics.viewLeft - objectMetrics.topLeft.x; + if (overflowLeft > 0) { + object.moveBy(overflowLeft, 0); + } + + // Bump any object that's off the right back inside. + var overflowRight = metrics.viewRight - objectMetrics.bottomRight.x; + if (overflowRight < 0) { + object.moveBy(overflowRight, 0); + } } - - // Bump any object that's below the bottom back inside. - var overflowBottom = metrics.viewBottom - objectMetrics.bottomRight.y; - if (overflowBottom < 0) { - object.moveBy(0, overflowBottom); - } - - // Bump any object that's off the left back inside. - var overflowLeft = metrics.viewLeft - objectMetrics.topLeft.x; - if (overflowLeft > 0) { - object.moveBy(overflowLeft, 0); - } - - // Bump any object that's off the right back inside. - var overflowRight = metrics.viewRight - objectMetrics.bottomRight.x; - if (overflowRight < 0) { - object.moveBy(overflowRight, 0); - } - if (e) { if (!e.group) { console.log('WARNING: Moved object in bounds but there was no' +