From d0fb99918f36fccbceea3b90a2ef65f7522894d5 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 25 Jan 2019 11:28:51 -0800 Subject: [PATCH] Ignore insertion markers when checking remaining capacity --- core/workspace.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/workspace.js b/core/workspace.js index 8d58ff87a..85a8f21d8 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -513,7 +513,18 @@ Blockly.Workspace.prototype.remainingCapacity = function() { if (isNaN(this.options.maxBlocks)) { return Infinity; } - return this.options.maxBlocks - this.getAllBlocks().length; + + // Insertion markers exist on the workspace for rendering reasons, but should + // be ignored in capacity calculation because they dissolve at the end of a + // drag. + var allBlocks = this.getAllBlocks(); + var allBlocksCount = allBlocks.length; + for (var i = 0; i < allBlocks.length; i++) { + if (allBlocks[i].isInsertionMarker()) { + allBlocksCount--; + } + } + return this.options.maxBlocks - allBlocksCount; }; /**