Fix #487: remove only selected copy of duplicate tracks in playlist

This commit is contained in:
Drew Weymouth
2024-09-29 13:04:43 -07:00
parent b6a082ddc1
commit 494ca677d8
2 changed files with 25 additions and 9 deletions
+24
View File
@@ -692,6 +692,30 @@ func (t *Tracklist) SelectedTrackIDs() []string {
return util.SelectedItemIDs(t.tracks)
}
// SelectedTrackIndexes returns the indexes of the selected tracks in the
// original sort order (ie if tracklist is sorted by some column), the indexes
// returned will correspond to the order of tracks when the list was initialized.
func (t *Tracklist) SelectedTrackIndexes() []int {
t.tracksMutex.RLock()
defer t.tracksMutex.RUnlock()
if t.sorting.SortOrder == SortNone {
idx := -1
return sharedutil.FilterMapSlice(t.tracks, func(t *util.TrackListModel) (int, bool) {
idx++
return idx, t.Selected
})
}
ids := sharedutil.ToSet(util.SelectedItemIDs(t.tracks))
idxs := make([]int, 0, len(ids))
for id := range ids {
idxs = append(idxs, slices.IndexFunc(t.tracks, func(t *util.TrackListModel) bool {
return t.Item.Metadata().ID == id
}))
}
return idxs
}
func (t *Tracklist) lenTracks() int {
t.tracksMutex.RLock()
defer t.tracksMutex.RUnlock()