From 40345384aa47e267115b9a201ab1e93bd6e1535f Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Wed, 7 Jun 2017 09:06:46 -0400 Subject: [PATCH 1/2] Select the last target instead of the first --- src/virtual-machine.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 19a4a8dd4..436ff60e8 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -379,7 +379,8 @@ class VirtualMachine extends EventEmitter { this.runtime.disposeTarget(sprite.clones[i]); // Ensure editing target is switched if we are deleting it. if (clone === currentEditingTarget) { - this.setEditingTarget(this.runtime.targets[0].id); + const lastTargetIndex = this.runtime.targets.length - 1; + this.setEditingTarget(this.runtime.targets[lastTargetIndex].id); } } // Sprite object should be deleted by GC. From 9c5d43e9d3f6da2c75cccc851756b7b355244cb4 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Mon, 12 Jun 2017 08:35:27 -0400 Subject: [PATCH 2/2] Enhance sprite delete behavior --- src/virtual-machine.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 436ff60e8..12e6e7a77 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -364,6 +364,8 @@ class VirtualMachine extends EventEmitter { */ deleteSprite (targetId) { const target = this.runtime.getTargetById(targetId); + const targetIndexBeforeDelete = this.runtime.targets.map(t => t.id).indexOf(target.id); + if (target) { if (!target.isSprite()) { throw new Error('Cannot delete non-sprite targets.'); @@ -379,8 +381,8 @@ class VirtualMachine extends EventEmitter { this.runtime.disposeTarget(sprite.clones[i]); // Ensure editing target is switched if we are deleting it. if (clone === currentEditingTarget) { - const lastTargetIndex = this.runtime.targets.length - 1; - this.setEditingTarget(this.runtime.targets[lastTargetIndex].id); + const nextTargetIndex = Math.min(this.runtime.targets.length - 1, targetIndexBeforeDelete); + this.setEditingTarget(this.runtime.targets[nextTargetIndex].id); } } // Sprite object should be deleted by GC.