From 99e6fd8eb44b3665bb98210761b519619d981585 Mon Sep 17 00:00:00 2001 From: Yuri Tatishchev Date: Tue, 10 Feb 2026 01:28:36 -0800 Subject: [PATCH] fix shuffle --- src/lib/player/store.svelte.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/lib/player/store.svelte.ts b/src/lib/player/store.svelte.ts index f30db06..96a39a0 100644 --- a/src/lib/player/store.svelte.ts +++ b/src/lib/player/store.svelte.ts @@ -146,13 +146,11 @@ class PlayerStore { this.queue.splice(insertIdx, 0, targetTrack); if (this.isShuffled) { - // Regenerate shuffle indices to be safe as queue shifted - this.reshuffle(); - // Attempt to place new track next in shuffle order? - // The reshuffle logic handles "current first", rest random. - // Ideally we want playNext to be deterministic even in shuffle. - // Getting complex. Let's stick to: "Play Next" inserts after current in Queue. - // If Shuffle is on, we force it to be next in shuffledIndices too. + // Shift indices that are >= insertIdx because we inserted a new item + this.shuffledIndices = this.shuffledIndices.map((i) => + i >= insertIdx ? i + 1 : i, + ); + const newIdx = insertIdx; // Find where current is in shuffledIndices