mirror of
https://github.com/google/blockly.git
synced 2026-01-10 10:27:08 +01:00
Fix search for closest
This commit is contained in:
@@ -645,13 +645,7 @@ Blockly.Connection.prototype.tighten_ = function() {
|
||||
* and 'radius' which is the distance.
|
||||
*/
|
||||
Blockly.Connection.prototype.closest = function(maxLimit, dx, dy) {
|
||||
var closestConnection = this.dbOpposite_.searchForClosest(this, maxLimit, dx,
|
||||
dy);
|
||||
if (closestConnection) {
|
||||
return {connection: closestConnection,
|
||||
radius: this.distanceFrom(closestConnection)};
|
||||
}
|
||||
return {connection: null, radius: maxLimit};
|
||||
return this.dbOpposite_.searchForClosest(this, maxLimit, dx, dy);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -221,14 +221,15 @@ Blockly.ConnectionDB.prototype.isInYRange_ = function(index, baseY, maxRadius) {
|
||||
* in the database and the current location (as a result of dragging).
|
||||
* @param {number} dy Vertical offset between this connection's location
|
||||
* in the database and the current location (as a result of dragging).
|
||||
* @return ?Blockly.Connection the closest valid connection.
|
||||
* another connection or null, and 'radius' which is the distance.
|
||||
* @return {!{connection: ?Blockly.Connection, radius: number}} Contains two
|
||||
* properties:' connection' which is either another connection or null,
|
||||
* and 'radius' which is the distance.
|
||||
*/
|
||||
Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, dx,
|
||||
dy) {
|
||||
// Don't bother.
|
||||
if (!this.length) {
|
||||
return null;
|
||||
return {connection: null, radius: maxRadius};
|
||||
}
|
||||
|
||||
// Stash the values of x and y from before the drag.
|
||||
@@ -273,7 +274,9 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, dx,
|
||||
// Reset the values of x and y.
|
||||
conn.x_ = baseX;
|
||||
conn.y_ = baseY;
|
||||
return bestConnection;
|
||||
|
||||
// If there were no valid connections, bestConnection will be null.
|
||||
return {connection: bestConnection, radius: bestRadius};
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -260,7 +260,8 @@ function helper_searchDB(db, x, y, radius, shared_workspace) {
|
||||
var tempConn = helper_createConnection(x, y,
|
||||
Blockly.NEXT_STATEMENT, shared_workspace);
|
||||
tempConn.sourceBlock_ = helper_makeSourceBlock(shared_workspace);
|
||||
return db.searchForClosest(tempConn, radius, 0, 0);
|
||||
var closest = db.searchForClosest(tempConn, radius, 0, 0);
|
||||
return closest.connection;
|
||||
}
|
||||
|
||||
function helper_makeSourceBlock(sharedWorkspace) {
|
||||
|
||||
Reference in New Issue
Block a user