From 8e6f39175ac538676d90d3cf1d8c699beab271d3 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 29 Jan 2019 11:57:43 -0800 Subject: [PATCH] Ignore insertion markers in getAllBlocks; add accessors for inseriton markers --- core/block_dragger.js | 16 ++++++++++++++++ core/gesture.js | 14 ++++++++++++++ core/insertion_marker_manager.js | 18 ++++++++++++++++++ core/workspace.js | 21 +++++++++------------ core/workspace_svg.js | 7 +++++++ 5 files changed, 64 insertions(+), 12 deletions(-) diff --git a/core/block_dragger.js b/core/block_dragger.js index 47624a335..4e9eddd1d 100644 --- a/core/block_dragger.js +++ b/core/block_dragger.js @@ -351,3 +351,19 @@ Blockly.BlockDragger.prototype.dragIcons_ = function(dxy) { data.icon.setIconLocation(goog.math.Coordinate.sum(data.location, dxy)); } }; + +/** + * Get a list of the insertion markers that currently exist. Drags have 0, 1, + * or 2 insertion markers. + * @return {!Array.} A possibly empty list of insertion + * marker blocks. + * @package + */ +Blockly.BlockDragger.prototype.getInsertionMarkers = function() { + // No insertion markers with the old style of dragged connection managers. + if (this.draggedConnectionManager_ && + this.draggedConnectionManager_.getInsertionMarkers) { + return this.draggedConnectionManager_.getInsertionMarkers(); + } + return []; +}; diff --git a/core/gesture.js b/core/gesture.js index 3df739569..a8e1177e0 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -940,3 +940,17 @@ Blockly.Gesture.prototype.isDragging = function() { Blockly.Gesture.prototype.hasStarted = function() { return this.hasStarted_; }; + +/** + * Get a list of the insertion markers that currently exist. Block drags have + * 0, 1, or 2 insertion markers. + * @return {!Array.} A possibly empty list of insertion + * marker blocks. + * @package + */ +Blockly.Gesture.prototype.getInsertionMarkers = function() { + if (this.blockDragger_) { + return this.blockDragger_.getInsertionMarkers(); + } + return []; +}; diff --git a/core/insertion_marker_manager.js b/core/insertion_marker_manager.js index f94677c8d..367fff46a 100644 --- a/core/insertion_marker_manager.js +++ b/core/insertion_marker_manager.js @@ -696,3 +696,21 @@ Blockly.InsertionMarkerManager.prototype.connectMarker_ = function() { }; /**** End insertion marker display functions ****/ + +/** + * Get a list of the insertion markers that currently exist. Drags have 0, 1, + * or 2 insertion markers. + * @return {!Array.} A possibly empty list of insertion + * marker blocks. + * @package + */ +Blockly.InsertionMarkerManager.prototype.getInsertionMarkers = function() { + var result = []; + if (this.firstMarker_) { + result.push(this.firstMarker_); + } + if (this.lastMarker_) { + result.push(this.lastMarker_); + } + return result; +}; diff --git a/core/workspace.js b/core/workspace.js index 85a8f21d8..bf9adc2b6 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -328,7 +328,14 @@ Blockly.Workspace.prototype.getAllBlocks = function(ordered) { blocks.push.apply(blocks, blocks[i].getChildren(false)); } } - return blocks; + + // Insertion markers exist on the workspace for rendering reasons, but aren't + // "real" blocks from a developer perspective. + var filtered = blocks.filter(function(block) { + return !block.isInsertionMarker(); + }); + + return filtered; }; /** @@ -514,17 +521,7 @@ Blockly.Workspace.prototype.remainingCapacity = function() { return Infinity; } - // 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; + return this.options.maxBlocks - this.getAllBlocks().length; }; /** diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 0ea797bae..34bad2df4 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -900,6 +900,13 @@ Blockly.WorkspaceSvg.prototype.render = function() { for (var i = blocks.length - 1; i >= 0; i--) { blocks[i].render(false); } + + if (this.currentGesture_) { + var imList = this.currentGesture_.getInsertionMarkers(); + for (var i = 0; i < imList.length; i++) { + imList[i].render(false); + } + } }; /**