From a8bfc3854562cba1b95d561faa4765872a615347 Mon Sep 17 00:00:00 2001 From: Sean Lip Date: Fri, 1 Jul 2016 15:17:32 -0700 Subject: [PATCH] Forbid any ancestor of the block containing the marked connection from being moved to said connection. --- accessible/clipboard.service.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/accessible/clipboard.service.js b/accessible/clipboard.service.js index 43c93b278..41e5bdb14 100644 --- a/accessible/clipboard.service.js +++ b/accessible/clipboard.service.js @@ -46,13 +46,20 @@ blocklyApp.ClipboardService = ng.core this.areConnectionsCompatible_(connection, nextConnection)); }, isMovableToMarkedConnection: function(block) { - // It should not be possible to move a block to one of its own - // connections. - if (this.markedConnection_ && - this.markedConnection_.sourceBlock_.id == block.id) { + // It should not be possible to move any ancestor of the block containing + // the marked spot to the marked spot. + if (!this.markedConnection_) { return false; } + var markedSpotAncestorBlock = this.markedConnection_.getSourceBlock(); + while (markedSpotAncestorBlock) { + if (markedSpotAncestorBlock.id == block.id) { + return false; + } + markedSpotAncestorBlock = markedSpotAncestorBlock.getParent(); + } + return this.canBeCopiedToMarkedConnection(block); }, canBeCopiedToMarkedConnection: function(block) {