Bug fix for swapping frames
This commit is contained in:
parent
08bb5ebc91
commit
702d4f38ea
23
src/App.vue
23
src/App.vue
@ -441,14 +441,27 @@
|
|||||||
const currentIndex = sprites.value.findIndex(sprite => sprite.id === id);
|
const currentIndex = sprites.value.findIndex(sprite => sprite.id === id);
|
||||||
if (currentIndex === -1) return;
|
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];
|
const newSprites = [...sprites.value];
|
||||||
|
|
||||||
// Remove the sprite from its current position
|
// Perform a swap between the two positions
|
||||||
const [movedSprite] = newSprites.splice(currentIndex, 1);
|
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
|
// Swap them
|
||||||
newSprites.splice(newIndex, 0, movedSprite);
|
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
|
// Update the sprites array
|
||||||
sprites.value = newSprites;
|
sprites.value = newSprites;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user