aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/queue.rs29
1 files changed, 21 insertions, 8 deletions
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 {
190 190
191 let current_pos = self.position; 191 let current_pos = self.position;
192 192
193 // Keep every track that's at a position <= current_pos (played + current) 193 // Find which tracks have been played (positions 0..=current_pos in shuffled order)
194 // These stay at exactly the same positions 194 // These are tracks whose shuffled_indices value is <= current_pos
195 let keep_count = current_pos + 1; 195 let mut played_track_paths: Vec<std::path::PathBuf> = Vec::new();
196 let mut new_tracks: Vec<Track> = self.tracks[..keep_count].to_vec(); 196 for i in 0..=current_pos {
197 if let Some(&idx) = self.shuffled_indices.get(i) {
198 if let Some(track) = self.tracks.get(idx) {
199 played_track_paths.push(track.path.clone());
200 }
201 }
202 }
203
204 // Keep the played tracks in their current order (shuffled order)
205 let mut new_tracks: Vec<Track> = Vec::new();
206 for path in &played_track_paths {
207 if let Some(track) = self.tracks.iter().find(|t| &t.path == path) {
208 new_tracks.push(track.clone());
209 }
210 }
197 211
198 // Find all tracks from original that are NOT in the kept portion 212 // Add remaining tracks from original in original order
199 // Insert them in their original order after current position
200 for orig_track in &self.original_tracks { 213 for orig_track in &self.original_tracks {
201 let in_kept = self.tracks[..keep_count].iter().any(|t| t.path == orig_track.path); 214 let is_played = played_track_paths.iter().any(|p| p == &orig_track.path);
202 if !in_kept { 215 if !is_played {
203 new_tracks.push(orig_track.clone()); 216 new_tracks.push(orig_track.clone());
204 } 217 }
205 } 218 }