dtas-all
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tracklist: update position when track is added


From: Eric Wong
Subject: [PATCH] tracklist: update position when track is added
Date: Thu, 10 Oct 2013 08:08:40 +0000

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(-)

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
-- 
1.8.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]