diff --git a/ui/browsing/playlistpage.go b/ui/browsing/playlistpage.go index 698b86b..66c9bad 100644 --- a/ui/browsing/playlistpage.go +++ b/ui/browsing/playlistpage.go @@ -132,12 +132,7 @@ func (a *PlaylistPage) load() { log.Printf("Failed to get playlist: %s", err.Error()) return } - // Playlists, like albums, have a sequential running order. We want the number column to - // represent the track's original position in the playlist, if the user applies a sort. - // Re-purpose the TrackNumber field for the track's position in the playlist, rather than its parent album. - for i, tr := range playlist.Tracks { - tr.TrackNumber = i + 1 - } + renumberTracks(playlist.Tracks) a.tracks = playlist.Tracks a.tracklist.SetTracks(playlist.Tracks) a.tracklist.SetNowPlaying(a.nowPlayingID) @@ -145,6 +140,15 @@ func (a *PlaylistPage) load() { a.header.Update(playlist) } +func renumberTracks(tracks []*mediaprovider.Track) { + // Playlists, like albums, have a sequential running order. We want the number column to + // represent the track's original position in the playlist, if the user applies a sort. + // Re-purpose the TrackNumber field for the track's position in the playlist, rather than its parent album. + for i, tr := range tracks { + tr.TrackNumber = i + 1 + } +} + func (a *PlaylistPage) onMoveSelectedToTop() { a.doSetNewTrackOrder(sharedutil.MoveToTop) } @@ -177,6 +181,7 @@ func (a *PlaylistPage) doSetNewTrackOrder(op sharedutil.TrackReorderOp) { if err := a.sm.Server.ReplacePlaylistTracks(a.playlistID, ids); err != nil { log.Printf("error updating playlist: %s", err.Error()) } else { + renumberTracks(newTracks) // force-switch back to unsorted view to show new track order a.tracklist.SetSorting(widgets.TracklistSort{}) a.tracklist.SetTracks(newTracks)