From ae1149f9aa4bfde639abf1635ce35fad64d96483 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 9 May 2026 17:25:27 +0200 Subject: Fix shuffle restore - track played tracks via shuffled_indices, not position --- src/queue.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/queue.rs b/src/queue.rs index 698fc1d..db329c6 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -190,16 +190,29 @@ impl Queue { let current_pos = self.position; - // Keep every track that's at a position <= current_pos (played + current) - // These stay at exactly the same positions - let keep_count = current_pos + 1; - let mut new_tracks: Vec = self.tracks[..keep_count].to_vec(); + // Find which tracks have been played (positions 0..=current_pos in shuffled order) + // These are tracks whose shuffled_indices value is <= current_pos + let mut played_track_paths: Vec = Vec::new(); + for i in 0..=current_pos { + if let Some(&idx) = self.shuffled_indices.get(i) { + if let Some(track) = self.tracks.get(idx) { + played_track_paths.push(track.path.clone()); + } + } + } + + // Keep the played tracks in their current order (shuffled order) + let mut new_tracks: Vec = Vec::new(); + for path in &played_track_paths { + if let Some(track) = self.tracks.iter().find(|t| &t.path == path) { + new_tracks.push(track.clone()); + } + } - // Find all tracks from original that are NOT in the kept portion - // Insert them in their original order after current position + // Add remaining tracks from original in original order for orig_track in &self.original_tracks { - let in_kept = self.tracks[..keep_count].iter().any(|t| t.path == orig_track.path); - if !in_kept { + let is_played = played_track_paths.iter().any(|p| p == &orig_track.path); + if !is_played { new_tracks.push(orig_track.clone()); } } -- cgit v1.2.3