bumpNeighbours_ function moved to block_svg.

Fixed #1009
This commit is contained in:
marisaleung
2017-04-17 15:12:37 -07:00
parent bc1ca547a4
commit 21bf339e5d
2 changed files with 48 additions and 36 deletions

View File

@@ -332,43 +332,9 @@ Blockly.Block.prototype.lastConnectionInStack_ = function() {
* connected should not coincidentally line up on screen.
* @private
*/
// TODO: Refactor to return early in headless mode.
Blockly.Block.prototype.bumpNeighbours_ = function() {
if (!this.workspace) {
return; // Deleted block.
}
if (Blockly.dragMode_ != Blockly.DRAG_NONE) {
return; // Don't bump blocks during a drag.
}
var rootBlock = this.getRootBlock();
if (rootBlock.isInFlyout) {
return; // Don't move blocks around in a flyout.
}
// Loop through every connection on this block.
var myConnections = this.getConnections_(false);
for (var i = 0, connection; connection = myConnections[i]; i++) {
// Spider down from this block bumping all sub-blocks.
if (connection.isConnected() && connection.isSuperior()) {
connection.targetBlock().bumpNeighbours_();
}
var neighbours = connection.neighbours_(Blockly.SNAP_RADIUS);
for (var j = 0, otherConnection; otherConnection = neighbours[j]; j++) {
// If both connections are connected, that's probably fine. But if
// either one of them is unconnected, then there could be confusion.
if (!connection.isConnected() || !otherConnection.isConnected()) {
// Only bump blocks if they are from different tree structures.
if (otherConnection.getSourceBlock().getRootBlock() != rootBlock) {
// Always bump the inferior block.
if (connection.isSuperior()) {
otherConnection.bumpAwayFrom_(connection);
} else {
connection.bumpAwayFrom_(otherConnection);
}
}
}
}
}
console.warn("Not expected to reach this bumpNeighbours_ function. The \
BlockSvg function for bumpNeighbours_ was expected to be called instead.")
};
/**