Commit 6f924e34 authored by Neil Fraser's avatar Neil Fraser

Speed up connection matching. Fix theoretical race condition.

parent c82c460d
This diff is collapsed.
......@@ -527,14 +527,14 @@ Blockly.Connection.prototype.closest = function(maxLimit, dx, dy) {
} while (targetSourceBlock);
// Only connections within the maxLimit radius.
var dx = currentX - db[yIndex].x_;
var dy = currentY - db[yIndex].y_;
var dx = currentX - connection.x_;
var dy = currentY - connection.y_;
var r = Math.sqrt(dx * dx + dy * dy);
if (r <= maxLimit) {
closestConnection = db[yIndex];
closestConnection = connection;
maxLimit = r;
}
return dy < maxLimit;
return Math.abs(dy) < maxLimit;
}
return {connection: closestConnection, radius: maxLimit};
};
......
......@@ -274,7 +274,9 @@ Blockly.Xml.domToBlock = function(workspace, xmlBlock, opt_reuseBlock) {
// Populating the connection database may be defered until after the blocks
// have renderend.
setTimeout(function() {
topBlock.setConnectionsHidden(false);
if (topBlock.workspace) { // Check that the block hasn't been deleted.
topBlock.setConnectionsHidden(false);
}
}, 1);
topBlock.updateDisabled();
// Fire an event to allow scrollbars to resize.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment