From 74ea1f1ffee0d4475b9a546acb896026ae4ef293 Mon Sep 17 00:00:00 2001 From: rachel-fenichel Date: Fri, 11 Mar 2016 18:07:26 -0800 Subject: [PATCH] consider the last block on the stack when looking for places to attach a dragging stack. --- core/block.js | 19 +++++++++++++++++++ core/block_svg.js | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/core/block.js b/core/block.js index 1fd24d0b0..7bc90abd0 100644 --- a/core/block.js +++ b/core/block.js @@ -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. diff --git a/core/block_svg.js b/core/block_svg.js index dec74441a..094615fce 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -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;