From 5c8ff88587f85bf6b756fbffc3ae32daf5039bbf Mon Sep 17 00:00:00 2001 From: rachel-fenichel Date: Tue, 5 Apr 2016 16:13:19 -0700 Subject: [PATCH] Keep a list of connections that are being dragged --- core/block_svg.js | 8 ++++++++ core/blockly.js | 2 ++ core/connection.js | 11 ++--------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/block_svg.js b/core/block_svg.js index efcacab5c..86c1ec94e 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -791,8 +791,11 @@ Blockly.BlockSvg.prototype.setDragging_ = function(adding) { group.translate_ = ''; group.skew_ = ''; this.addDragging(); + Blockly.draggingConnections_ = + Blockly.draggingConnections_.concat(this.getConnections_(true)); } else { this.removeDragging(); + Blockly.draggingConnections_ = []; } // Recurse through all blocks attached under this one. for (var i = 0; i < this.childBlocks_.length; i++) { @@ -854,6 +857,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; diff --git a/core/blockly.js b/core/blockly.js index 85d311e6d..109c694ff 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -82,6 +82,8 @@ Blockly.highlightedConnection_ = null; */ Blockly.localConnection_ = null; +Blockly.draggingConnections_ = []; + /** * Contents of the local clipboard. * @type {Element} diff --git a/core/connection.js b/core/connection.js index 89b4aef27..549cf3f10 100644 --- a/core/connection.js +++ b/core/connection.js @@ -400,15 +400,8 @@ Blockly.Connection.prototype.isConnectionAllowed = function(candidate, } // Don't let blocks try to connect to themselves or ones they nest. - var targetSourceBlock = candidate.getSourceBlock(); - var sourceBlock = this.sourceBlock_; - if (targetSourceBlock && sourceBlock) { - do { - if (sourceBlock == targetSourceBlock) { - return false; - } - targetSourceBlock = targetSourceBlock.getParent(); - } while (targetSourceBlock); + if (Blockly.draggingConnections_.indexOf(candidate) != -1) { + return false; } return true;