mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
Merge pull request #2243 from rachel-fenichel/getAllBlocks_insertionMarkers
Ignore insertion markers in getAllBlocks; add accessors for insertion markers
This commit is contained in:
@@ -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.<!Blockly.BlockSvg>} 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 [];
|
||||
};
|
||||
|
||||
@@ -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.<!Blockly.BlockSvg>} A possibly empty list of insertion
|
||||
* marker blocks.
|
||||
* @package
|
||||
*/
|
||||
Blockly.Gesture.prototype.getInsertionMarkers = function() {
|
||||
if (this.blockDragger_) {
|
||||
return this.blockDragger_.getInsertionMarkers();
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
@@ -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.<!Blockly.BlockSvg>} 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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user