Skip to content

Commit

Permalink
Merge pull request #2147 from rachel-fenichel/bugfix/2131
Browse files Browse the repository at this point in the history
Allow statement connections to connect around block stacks during drags
  • Loading branch information
rachel-fenichel committed Nov 30, 2018
2 parents 7ec5599 + 1553096 commit 3cbb137
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
37 changes: 11 additions & 26 deletions core/connection.js
Expand Up @@ -355,34 +355,19 @@ Blockly.Connection.prototype.canConnectToPrevious_ = function(candidate) {
return false;
}

var firstStatementConnection =
this.sourceBlock_.getFirstStatementConnection();
var isFirstStatementConnection = this == firstStatementConnection;
var isNextConnection = this == this.sourceBlock_.nextConnection;

// Complex blocks with no previous connection will not be allowed to connect
// mid-stack.
var sourceHasPreviousConn = this.sourceBlock_.previousConnection != null;

if (isNextConnection ||
(isFirstStatementConnection && !sourceHasPreviousConn)) {
// If the candidate is the first connection in a stack, we can connect.
if (!candidate.targetConnection) {
return true;
}
if (!candidate.targetConnection) {
return true;
}

var targetBlock = candidate.targetBlock();
// If it is connected to a real block, game over.
if (!targetBlock.isInsertionMarker()) {
return false;
}
// If it's connected to an insertion marker but that insertion marker
// is the first block in a stack, it's still fine. If that insertion
// marker is in the middle of a stack, it won't work.
return !targetBlock.getPreviousBlock();
var targetBlock = candidate.targetBlock();
// If it is connected to a real block, game over.
if (!targetBlock.isInsertionMarker()) {
return false;
}
console.warn('Returning false by default from canConnectToPrevious_.');
return false;
// If it's connected to an insertion marker but that insertion marker
// is the first block in a stack, it's still fine. If that insertion
// marker is in the middle of a stack, it won't work.
return !targetBlock.getPreviousBlock();
};

/**
Expand Down
3 changes: 2 additions & 1 deletion core/insertion_marker_manager.js
Expand Up @@ -335,7 +335,8 @@ Blockly.InsertionMarkerManager.prototype.shouldUpdatePreviews_ = function(
// Decide whether the new connection has higher priority.
if (this.localConnection_ && this.closestConnection_) {
// The connection was the same as the current connection.
if (this.closestConnection_ == candidateClosest) {
if (this.closestConnection_ == candidateClosest &&
this.localConnection_ == candidateLocal) {
return false;
}
var xDiff = this.localConnection_.x_ + dxy.x - this.closestConnection_.x_;
Expand Down

0 comments on commit 3cbb137

Please sign in to comment.