From 064e91d9b334f544d5ac2ff57d06d338dfcdb3d8 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 10 Oct 2013 06:36:21 +0000 Subject: tracklist: update position when track is added We don't want to repeat tracks if a track was added to a spot before the current position on the tracklist. --- lib/dtas/tracklist.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/dtas/tracklist.rb') diff --git a/lib/dtas/tracklist.rb b/lib/dtas/tracklist.rb index 325db20..b6f02c3 100644 --- a/lib/dtas/tracklist.rb +++ b/lib/dtas/tracklist.rb @@ -91,10 +91,18 @@ class DTAS::Tracklist # :nodoc: idx = by_track_id[after_track_id] or raise ArgumentError, "after_track_id invalid" @list[idx, 1] = [ @list[idx], track ] - @pos = idx + 1 if set_as_current + if set_as_current + @pos = idx + 1 + else + @pos += 1 if @pos >= idx + end else # nil = first_track @list.unshift(track) - @pos = 0 if set_as_current + if set_as_current + @pos = 0 + else + @pos += 1 if @pos >= 0 + end end track.object_id end -- cgit v1.2.3-24-ge0c7