about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/dtas/tracklist.rb7
-rw-r--r--test/test_tracklist.rb1
2 files changed, 6 insertions, 2 deletions
diff --git a/lib/dtas/tracklist.rb b/lib/dtas/tracklist.rb
index 2336545..01339cc 100644
--- a/lib/dtas/tracklist.rb
+++ b/lib/dtas/tracklist.rb
@@ -32,6 +32,7 @@ class DTAS::Tracklist
   def initialize
     TL_DEFAULTS.each { |k,v| instance_variable_set("@#{k}", v) }
     @list = []
+    @goto_pos = nil
   end
 
   def size
@@ -61,7 +62,8 @@ class DTAS::Tracklist
 
   def next_track(repeat_ok = true)
     return if @list.empty?
-    next_pos = @pos + 1
+    next_pos = @goto_pos || @pos + 1
+    @goto_pos = nil
     if @list[next_pos]
       @pos = next_pos
     elsif @repeat && repeat_ok
@@ -102,8 +104,9 @@ class DTAS::Tracklist
   def go_to(track_id)
     by_track_id = _track_id_map
     if idx = by_track_id[track_id]
-      return @list[@pos = idx]
+      return @list[@goto_pos = idx]
     end
+    @goto_pos = nil
     # noop if track_id is invalid
   end
 end
diff --git a/test/test_tracklist.rb b/test/test_tracklist.rb
index cc462c5..e4ca9ac 100644
--- a/test/test_tracklist.rb
+++ b/test/test_tracklist.rb
@@ -49,6 +49,7 @@ class TestTracklist < Testcase
     tl.instance_variable_get(:@list).replace(%w(a b c d e f g))
     mapping = _build_mapping(tl)
     assert_equal 'f', tl.go_to(mapping['f'])
+    assert_equal 'f', tl.next_track
     assert_nil tl.go_to(1 << 128)
     assert_equal 'g', tl.next_track
   end