« get me outta code hell

http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/pickers2.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/pickers2.js')
-rw-r--r--src/pickers2.js23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/pickers2.js b/src/pickers2.js
index e36d257..af3fc2a 100644
--- a/src/pickers2.js
+++ b/src/pickers2.js
@@ -52,13 +52,28 @@ class HistoryController {
     }
   }
 
-  getNextTrack() {
+  getNextTrack(move = true) {
     // Moves the timeline index forwards and returns the track at the new index
     // (while refilling the timeline, so that the "up next" list is still full,
     // and so the picker is called if there is no track at the current index).
-    this.timelineIndex++
-    this.fillTimeline()
-    return this.currentTrack
+    if (move) {
+      this.timelineIndex++
+      this.fillTimeline()
+      return this.currentTrack
+    } else {
+      return this.timeline[this.timelineIndex + 1]
+    }
+  }
+
+  getBackTrack(move = true) {
+    if (move) {
+      if (this.timelineIndex > 0) {
+        this.timelineIndex--
+      }
+      return this.currentTrack
+    } else {
+      return this.timeline[Math.max(this.timelineIndex - 1, 0)]
+    }
   }
 
   get currentTrack() {