From 702d4f38eaa14123ad02d4be0a5df7753ccea39f Mon Sep 17 00:00:00 2001 From: Dennis Postma Date: Sun, 6 Apr 2025 03:14:33 +0200 Subject: [PATCH] Bug fix for swapping frames --- src/App.vue | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/App.vue b/src/App.vue index c182139..0b5c65c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -441,14 +441,27 @@ const currentIndex = sprites.value.findIndex(sprite => sprite.id === id); if (currentIndex === -1) return; - // Create a new sprites array + // If we're trying to move to the same position, do nothing + if (currentIndex === newIndex) return; + + // Create a copy of the sprites array const newSprites = [...sprites.value]; - // Remove the sprite from its current position - const [movedSprite] = newSprites.splice(currentIndex, 1); + // Perform a swap between the two positions + if (newIndex < sprites.value.length) { + // Get references to both sprites + const movingSprite = { ...newSprites[currentIndex] }; + const targetSprite = { ...newSprites[newIndex] }; - // Insert the sprite at the new position - newSprites.splice(newIndex, 0, movedSprite); + // Swap them + newSprites[currentIndex] = targetSprite; + newSprites[newIndex] = movingSprite; + } else { + // If dragging to an empty cell (beyond the array length) + // Use the original reordering logic + const [movedSprite] = newSprites.splice(currentIndex, 1); + newSprites.splice(newIndex, 0, movedSprite); + } // Update the sprites array sprites.value = newSprites;