« get me outta code hell

Shift-up/down to skip tracks - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-06-02 12:51:55 -0300
committerFlorrie <towerofnix@gmail.com>2018-06-02 12:51:55 -0300
commitb89f230581e7a921f74fa9f6c40aa5da14a81859 (patch)
treee9de5fa3774811907b5aea2e545f5caba71149f8
parenta5877baf3461d6607ccbe2755712bd790b62d8db (diff)
Shift-up/down to skip tracks
-rw-r--r--ui.js33
1 files changed, 32 insertions, 1 deletions
diff --git a/ui.js b/ui.js
index 1a583ab..57b2d9f 100644
--- a/ui.js
+++ b/ui.js
@@ -106,6 +106,10 @@ class AppElement extends FocusElement {
       this.seekBack(10)
     } else if (telc.isCaselessLetter(keyBuf, 'p') || telc.isCaselessLetter(keyBuf, 'k')) {
       this.togglePause()
+    } else if (telc.isShiftUp(keyBuf)) {
+      this.playPreviousTrack(this.playingTrack)
+    } else if (telc.isShiftDown(keyBuf)) {
+      this.playNextTrack(this.playingTrack)
     } else {
       super.keyPressed(keyBuf)
     }
@@ -159,7 +163,9 @@ class AppElement extends FocusElement {
         items.splice(items.indexOf(item), 1)
       }
 
-      if (afterItem && items.includes(afterItem)) {
+      if (afterItem === 'FRONT') {
+        items.unshift(item)
+      } else if (afterItem && items.includes(afterItem)) {
         items.splice(items.indexOf(afterItem) + 1, 0, item)
       } else {
         items.push(item)
@@ -266,6 +272,31 @@ class AppElement extends FocusElement {
 
     this.playGrouplikeItem(queue.items[queueIndex], false)
   }
+
+  playPreviousTrack(track) {
+    const queue = this.queueGrouplike
+    let queueIndex = queue.items.indexOf(track)
+    if (queueIndex === -1) {
+      queueIndex = queue.items.length
+    }
+    queueIndex--
+
+    if (queueIndex < 0) {
+      const parent = track[parentSymbol]
+      if (!parent) {
+        return
+      }
+      const index = parent.items.indexOf(track)
+      const previousItem = parent.items[index - 1]
+      if (!previousItem) {
+        return
+      }
+      this.queueGrouplikeItem(previousItem, false, 'FRONT')
+      queueIndex = 0
+    }
+
+    this.playGrouplikeItem(queue.items[queueIndex], false)
+  }
 }
 
 class GrouplikeListingElement extends ListScrollForm {