From da539ea6cd0b0efb4692a7ae8c668f0dddbb80de Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Tue, 10 Apr 2018 14:31:49 -0400 Subject: [PATCH 1/2] Only select the original target after a drag. This allows you to still drag clones around, but when you stop dragging, the original sprite gets selected. --- src/virtual-machine.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/virtual-machine.js b/src/virtual-machine.js index abe4b69b..e9b0b91c 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -900,7 +900,7 @@ class VirtualMachine extends EventEmitter { if (target) { this._dragTarget = null; target.stopDrag(); - this.setEditingTarget(target.id); + this.setEditingTarget(target.sprite.clones[0].id); } } From 4a9adcc3d9699c525b00347a67f108e008f69cf3 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Wed, 11 Apr 2018 09:12:43 -0400 Subject: [PATCH 2/2] Make stopDrag deal with bare targets and add tests --- src/virtual-machine.js | 3 ++- test/unit/virtual-machine.js | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/virtual-machine.js b/src/virtual-machine.js index e9b0b91c..71ba39d7 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -900,7 +900,8 @@ class VirtualMachine extends EventEmitter { if (target) { this._dragTarget = null; target.stopDrag(); - this.setEditingTarget(target.sprite.clones[0].id); + this.setEditingTarget(target.sprite && target.sprite.clones[0] ? + target.sprite.clones[0].id : target.id); } } diff --git a/test/unit/virtual-machine.js b/test/unit/virtual-machine.js index ceee87b7..c8cb6596 100644 --- a/test/unit/virtual-machine.js +++ b/test/unit/virtual-machine.js @@ -379,3 +379,30 @@ test('drag IO redirect', t => { t.equal(sprite2Info[1], 'sprite2 info 2'); t.end(); }); + +test('select original after dragging clone', t => { + const vm = new VirtualMachine(); + let newEditingTargetId = null; + vm.setEditingTarget = id => { + newEditingTargetId = id; + }; + vm.runtime.targets = [ + { + id: 'sprite1_clone', + sprite: {clones: [{id: 'sprite1_original'}]}, + stopDrag: () => {} + }, { + id: 'sprite2', + stopDrag: () => {} + } + ]; + + // Stop drag on a bare target selects that target + vm.stopDrag('sprite2'); + t.equal(newEditingTargetId, 'sprite2'); + + // Stop drag on target with parent sprite selects the 0th clone of that sprite + vm.stopDrag('sprite1_clone'); + t.equal(newEditingTargetId, 'sprite1_original'); + t.end(); +});