From d8b431ae611560ec02d0697bbfe561e472e9626d Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Tue, 27 Aug 2019 10:12:49 -0700 Subject: [PATCH] Fixes not being able to move block with parent (#2920) * Fixes not being able to move block with parent --- core/keyboard_nav/navigation.js | 10 +++++----- tests/mocha/navigation_test.js | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/core/keyboard_nav/navigation.js b/core/keyboard_nav/navigation.js index c50db02ad..97659bd2c 100644 --- a/core/keyboard_nav/navigation.js +++ b/core/keyboard_nav/navigation.js @@ -486,9 +486,9 @@ Blockly.navigation.modify = function() { /** * If the two blocks are compatible move the moving connection to the target * connection and connect them. - * @param {Blockly.Connection} movingConnection The connection that is being + * @param {!Blockly.Connection} movingConnection The connection that is being * moved. - * @param {Blockly.Connection} destConnection The connection to be moved to. + * @param {!Blockly.Connection} destConnection The connection to be moved to. * @return {boolean} True if the connections were connected, false otherwise. * @private */ @@ -497,9 +497,9 @@ Blockly.navigation.moveAndConnect_ = function(movingConnection, destConnection) if (destConnection.canConnectWithReason_(movingConnection) == Blockly.Connection.CAN_CONNECT) { - if (destConnection.type == Blockly.PREVIOUS_STATEMENT || - destConnection.type == Blockly.OUTPUT_VALUE) { - movingBlock.positionNearConnection(movingConnection, destConnection); + if (!destConnection.isSuperior()) { + var rootBlock = movingBlock.getRootBlock(); + rootBlock.positionNearConnection(movingConnection, destConnection); } destConnection.connect(movingConnection); return true; diff --git a/tests/mocha/navigation_test.js b/tests/mocha/navigation_test.js index 71ec15533..1307b3023 100644 --- a/tests/mocha/navigation_test.js +++ b/tests/mocha/navigation_test.js @@ -507,6 +507,16 @@ suite('Navigation', function() { chai.assert.equal(this.basicBlock.nextConnection.targetBlock(), this.basicBlock4); chai.assert.equal(this.basicBlock3.nextConnection.targetConnection, null); }); + + test('Connect cursor with parents', function() { + var markedLocation = this.basicBlock3.previousConnection; + var cursorLocation = this.basicBlock2.nextConnection; + + Blockly.navigation.connect(cursorLocation, markedLocation); + + chai.assert.equal(this.basicBlock3.previousConnection.targetBlock(), this.basicBlock2); + }); + });