From 6bbeb2d0fee77d03c872ef2417ca16a7e19cfac2 Mon Sep 17 00:00:00 2001 From: Tim Mickel Date: Mon, 2 May 2016 22:31:00 -0400 Subject: [PATCH] Shuffle moveBlock to allow case where e.oldParent !== undefined --- src/engine/runtime.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/engine/runtime.js b/src/engine/runtime.js index ac1652c7..88cc2989 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -130,8 +130,23 @@ Runtime.prototype.changeBlock = function (args) { Runtime.prototype.moveBlock = function (e) { var _this = this; - // Block has a new parent - if (e.oldParent === undefined && e.newParent !== undefined) { + // Block was removed from parent + if (e.newParent === undefined && e.oldParent !== undefined) { + // Add stack + _this.stacks.push(e.id); + + // Update old parent + if (e.oldField === undefined) { + _this.blocks[e.oldParent].next = null; + } else { + delete _this.blocks[e.oldParent].fields[e.oldField]; + } + } else if (e.newParent !== undefined) { + // Block was moved to a new parent + // Either happens because it was previously parentless + // (e.oldParent === undefined) + // or because a block was moved in front of it. + // Remove stack _this._deleteStack(e.id); @@ -146,19 +161,6 @@ Runtime.prototype.moveBlock = function (e) { }; } } - - // Block was removed from parent - if (e.newParent === undefined && e.oldParent !== undefined) { - // Add stack - _this.stacks.push(e.id); - - // Update old parent - if (e.oldField === undefined) { - _this.blocks[e.oldParent].next = null; - } else { - delete _this.blocks[e.oldParent].fields[e.oldField]; - } - } }; /**