This commit is contained in:
Rachel Fenichel 2016-02-29 15:50:12 -08:00
parent 42065aec3d
commit d29ffdc283
2 changed files with 53 additions and 53 deletions

View file

@ -225,23 +225,23 @@ Blockly.Connection.prototype.checkConnection_ = function(target) {
* @return {boolean} True if the connection is allowed, false otherwise.
*/
Blockly.Connection.prototype.isConnectionAllowed = function(candidate,
maxRadius) {
maxRadius) {
if (this.distanceFrom(candidate) > maxRadius) {
return false;
return false;
}
// Type checking
var canConnect = this.canConnectWithReason_(candidate);
if (canConnect != Blockly.Connection.CAN_CONNECT
&& canConnect != Blockly.Connection.REASON_MUST_DISCONNECT) {
return false;
if (canConnect != Blockly.Connection.CAN_CONNECT &&
canConnect != Blockly.Connection.REASON_MUST_DISCONNECT) {
return false;
}
// Don't offer to connect an already connected left (male) value plug to
// an available right (female) value plug. Don't offer to connect the
// bottom of a statement block to one that's already connected.
if (candidate.type == Blockly.OUTPUT_VALUE
|| candidate.type == Blockly.PREVIOUS_STATEMENT) {
if (candidate.type == Blockly.OUTPUT_VALUE ||
candidate.type == Blockly.PREVIOUS_STATEMENT) {
if (candidate.targetConnection || this.targetConnection) {
return false;
}

View file

@ -149,14 +149,14 @@ Blockly.ConnectionDB.prototype.removeConnection_ = function(connection) {
/**
* Find all nearby connections to the given connection.
* Type checking does not apply, since this function is used for bumping.
* @param {Blockly.Connection} connection The connection whose neighbours should
* @param {!Blockly.Connection} connection The connection whose neighbours should
* be returned.
* @param {number} maxRadius The maximum radius to another connection.
* @return {!Array.<Blockly.Connection>} List of connections.
* @private
*/
Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) {
var db = this;
var db = this;
var currentX = connection.x_;
var currentY = connection.y_;
@ -226,54 +226,54 @@ Blockly.ConnectionDB.prototype.isInYRange_ = function(index, baseY, maxRadius) {
*/
Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, dx,
dy) {
// Don't bother.
if (this.length == 0) {
return null;
// Don't bother.
if (!this.length) {
return null;
}
// Stash the values of x and y from before the drag.
var baseY = conn.y_;
var baseX = conn.x_;
conn.x_ = baseX + dx;
conn.y_ = baseY + dy;
// findPositionForConnection finds an index for insertion, which is always
// after any block with the same y index. We want to search both forward
// and back, so search on both sides of the index.
var closestIndex = this.findPositionForConnection_(conn);
var bestConnection = null;
var bestRadius = maxRadius;
var temp;
// Walk forward and back on the y axis looking for the closest x,y point.
var pointerMin = closestIndex - 1;
while (pointerMin >= 0 &&
this.isInYRange_(pointerMin, conn.y_, maxRadius)) {
temp = this[pointerMin];
if (conn.isConnectionAllowed(temp, bestRadius)) {
bestConnection = temp;
bestRadius = temp.distanceFrom(conn);
}
pointerMin--;
}
// Stash the values of x and y from before the drag.
var baseY = conn.y_;
var baseX = conn.x_;
conn.x_ = baseX + dx;
conn.y_ = baseY + dy;
// findPositionForConnection finds an index for insertion, which is always
// after any block with the same y index. We want to search both forward
// and back, so search on both sides of the index.
var closestIndex = this.findPositionForConnection_(conn);
var bestConnection = null;
var bestRadius = maxRadius;
var temp;
// Walk forward and back on the y axis looking for the closest x,y point.
var pointerMin = closestIndex - 1;
while (pointerMin >= 0 &&
this.isInYRange_(pointerMin, conn.y_, maxRadius)) {
temp = this[pointerMin];
if (conn.isConnectionAllowed(temp, bestRadius)) {
bestConnection = temp;
bestRadius = temp.distanceFrom(conn);
}
pointerMin--;
var pointerMax = closestIndex;
while (pointerMax < this.length && this.isInYRange_(pointerMax, conn.y_,
maxRadius)) {
temp = this[pointerMax];
if (conn.isConnectionAllowed(temp, bestRadius)) {
bestConnection = temp;
bestRadius = temp.distanceFrom(conn);
}
pointerMax++;
}
var pointerMax = closestIndex;
while (pointerMax < this.length && this.isInYRange_(pointerMax, conn.y_,
maxRadius)) {
temp = this[pointerMax];
if (conn.isConnectionAllowed(temp, bestRadius)) {
bestConnection = temp;
bestRadius = temp.distanceFrom(conn);
}
pointerMax++;
}
// Reset the values of x and y.
conn.x_ = baseX;
conn.y_ = baseY;
return bestConnection;
// Reset the values of x and y.
conn.x_ = baseX;
conn.y_ = baseY;
return bestConnection;
};
/**