Skip to content

Commit

Permalink
Fix #487: remove only selected copy of duplicate tracks in playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Sep 29, 2024
1 parent b6a082d commit 494ca67
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
10 changes: 1 addition & 9 deletions ui/browsing/playlistpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,7 @@ func (a *PlaylistPage) doSetNewTrackOrder(ids []string, newPos int) {
}

func (a *PlaylistPage) onRemoveSelectedFromPlaylist() {
ids := a.tracklist.SelectedTrackIDs()
sel := sharedutil.ToSet(ids)
idxs := make([]int, 0, len(sel))
for i, tr := range a.tracks {
if _, ok := sel[tr.ID]; ok {
idxs = append(idxs, i)
}
}
a.sm.Server.RemovePlaylistTracks(a.playlistID, idxs)
a.sm.Server.RemovePlaylistTracks(a.playlistID, a.tracklist.SelectedTrackIndexes())
a.tracklist.UnselectAll()
a.Reload()
}
Expand Down
24 changes: 24 additions & 0 deletions ui/widgets/tracklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 494ca67

Please sign in to comment.