Browse Source

Fix draggable object deletion. Issue #1505

Pascal Schade 1 year ago
parent
commit
40a94a1c8a
1 changed files with 10 additions and 4 deletions
  1. 10 4
      nicegui/elements/scene.js

+ 10 - 4
nicegui/elements/scene.js

@@ -326,14 +326,20 @@ export default {
     },
     draggable(object_id, value) {
       if (!this.objects.has(object_id)) return;
-      if (value) this.draggable_objects.push(this.objects.get(object_id));
-      else this.draggable_objects.pop(this.objects.get(object_id));
+      const object = this.objects.get(object_id);
+      if (value) this.draggable_objects.push(object);
+      else {
+        const index = this.draggable_objects.indexOf(object);
+        if (index != -1) this.draggable_objects.splice(index, 1);
+      }
     },
     delete(object_id) {
       if (!this.objects.has(object_id)) return;
-      this.objects.get(object_id).removeFromParent();
+      const object = this.objects.get(object_id);
+      object.removeFromParent();
       this.objects.delete(object_id);
-      this.draggable_objects.pop(this.objects.get(object_id));
+      const index = this.draggable_objects.indexOf(object);
+      if (index != -1) this.draggable_objects.splice(index, 1);
     },
     set_texture_url(object_id, url) {
       if (!this.objects.has(object_id)) return;