Merge pull request #284 from rachel-fenichel/feature/last_in_stack

consider the last block on the stack when looking for places to attac…
This commit is contained in:
rachel-fenichel
2016-03-14 13:29:11 -07:00
2 changed files with 24 additions and 0 deletions

View File

@@ -278,6 +278,25 @@ Blockly.Block.prototype.getConnections_ = function(all) {
return myConnections;
};
/**
* Walks down a stack of blocks and finds the last next connection on the stack.
* @return {Blockly.Connection} The last next connection on the stack, or null.
* @private
*/
Blockly.Block.prototype.lastConnectionInStack_ = function() {
var nextConnection = this.nextConnection;
while (nextConnection) {
var nextBlock = nextConnection.targetBlock();
if (!nextBlock) {
// Found a next connection with nothing on the other side.
return nextConnection;
}
nextConnection = nextBlock.nextConnection;
}
// Ran out of next connections.
return null;
};
/**
* Bump unconnected blocks out of alignment. Two blocks which aren't actually
* connected should not coincidentally line up on screen.

View File

@@ -822,6 +822,11 @@ Blockly.BlockSvg.prototype.onMouseMove_ = function(e) {
// Check to see if any of this block's connections are within range of
// another block's connection.
var myConnections = this.getConnections_(false);
// Also check the last connection on this stack
var lastOnStack = this.lastConnectionInStack_();
if (lastOnStack && lastOnStack != this.nextConnection) {
myConnections.push(lastOnStack);
}
var closestConnection = null;
var localConnection = null;
var radiusConnection = Blockly.SNAP_RADIUS;