Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 28 additions & 26 deletions core/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) {
// Attempt to reattach the orphan at the end of the newly inserted
// block. Since this block may be a row, walk down to the end
// or to the first (and only) shadow block.
var connection = Blockly.Connection.lastConnectionInRow(
var connection = Blockly.Connection.getConnectionForOrphanedOutput(
childBlock, orphanBlock);
if (connection) {
orphanBlock.outputConnection.connect(connection);
Expand Down Expand Up @@ -372,30 +372,31 @@ Blockly.Connection.connectReciprocally_ = function(first, second) {
};

/**
* Does the given block have one and only one connection point that will accept
* an orphaned block?
* Returns the single connection on the block that will accept the orphaned
* block, if one can be found. If the block has multiple compatible connections
* (even if they are filled) this returns null. If the block has no compatible
* connections, this returns null.
* @param {!Blockly.Block} block The superior block.
* @param {!Blockly.Block} orphanBlock The inferior block.
* @return {Blockly.Connection} The suitable connection point on 'block',
* or null.
* @private
*/
Blockly.Connection.singleConnection_ = function(block, orphanBlock) {
var connection = null;
Blockly.Connection.getSingleConnection_ = function(block, orphanBlock) {
var foundConnection = null;
var output = orphanBlock.outputConnection;
for (var i = 0; i < block.inputList.length; i++) {
var thisConnection = block.inputList[i].connection;
var typeChecker = output.getConnectionChecker();
if (thisConnection &&
thisConnection.type == Blockly.connectionTypes.INPUT_VALUE &&
typeChecker.canConnect(output, thisConnection, false)) {
if (connection) {
var typeChecker = output.getConnectionChecker();

for (var i = 0, input; (input = block.inputList[i]); i++) {
var connection = input.connection;
if (connection && typeChecker.canConnect(output, connection, false)) {
if (foundConnection) {
return null; // More than one connection.
}
connection = thisConnection;
foundConnection = connection;
}
}
return connection;
return foundConnection;
};

/**
Expand All @@ -410,18 +411,19 @@ Blockly.Connection.singleConnection_ = function(block, orphanBlock) {
* of blocks, or null.
* @package
*/
Blockly.Connection.lastConnectionInRow = function(startBlock, orphanBlock) {
var newBlock = startBlock;
var connection;
while ((connection = Blockly.Connection.singleConnection_(
/** @type {!Blockly.Block} */ (newBlock), orphanBlock))) {
newBlock = connection.targetBlock();
if (!newBlock || newBlock.isShadow()) {
return connection;
}
}
return null;
};
Blockly.Connection.getConnectionForOrphanedOutput =
function(startBlock, orphanBlock) {
var newBlock = startBlock;
var connection;
while ((connection = Blockly.Connection.getSingleConnection_(
/** @type {!Blockly.Block} */ (newBlock), orphanBlock))) {
newBlock = connection.targetBlock();
if (!newBlock || newBlock.isShadow()) {
return connection;
}
}
return null;
};

/**
* Disconnect this connection.
Expand Down
14 changes: 4 additions & 10 deletions core/renderers/common/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,19 +248,13 @@ Blockly.blockRendering.Renderer.prototype.orphanCanConnectAtEnd =
function(topBlock, orphanBlock, localType) {
var orphanConnection = null;
var lastConnection = null;
if (localType ==
Blockly.connectionTypes
.OUTPUT_VALUE) { // We are replacing an output.
if (localType == Blockly.connectionTypes.OUTPUT_VALUE) {
orphanConnection = orphanBlock.outputConnection;
// TODO: I don't think this function necessarily has the correct logic,
// but for now it is being kept for behavioral backwards-compat.
lastConnection = Blockly.Connection
.lastConnectionInRow(
lastConnection =
Blockly.Connection.getConnectionForOrphanedOutput(
/** @type {!Blockly.Block} **/ (topBlock), orphanBlock);
} else { // We are replacing a previous.
} else {
orphanConnection = orphanBlock.previousConnection;
// TODO: This lives on the block while lastConnectionInRow lives on
// on the connection. Something is fishy.
lastConnection = topBlock.lastConnectionInStack();
}

Expand Down
Loading