« get me outta code hell

Update tui-lib - fix crash when queue gets shorter - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/ui.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2019-04-02 08:13:59 -0300
committerFlorrie <towerofnix@gmail.com>2019-04-02 08:20:25 -0300
commit253a637e08365ad5d78215f90ca4c4dcbb6680a8 (patch)
treee806dade979ded19640e0eee74db84220df0b187 /ui.js
parente4a6de4eee866aabccd4b258c1f333799c9c8e68 (diff)
Update tui-lib - fix crash when queue gets shorter
Previously (on Avatar), removing tracks from the queue would cause
a crash if the queue listing was scrolled down. This update fixes that.
Diffstat (limited to 'ui.js')
-rw-r--r--ui.js25
1 files changed, 22 insertions, 3 deletions
diff --git a/ui.js b/ui.js
index de2226a..e78caa9 100644
--- a/ui.js
+++ b/ui.js
@@ -722,13 +722,31 @@ class AppElement extends FocusElement {
       }
 
       const items = this.queueGrouplike.items
+
+      // If we're unqueueing the item which is currently focused by the cursor,
+      // just move the cursor ahead.
+      if (item === focusItem) {
+        focusItem = items[items.indexOf(focusItem) + 1]
+        // ...Unless that puts it at past the end of the list, in which case, move
+        // it behind the item we're removing.
+        if (!focusItem) {
+          focusItem = items[items.length - 2]
+        }
+      }
+
       if (items.includes(item)) {
         items.splice(items.indexOf(item), 1)
       }
     }
 
+    let focusItem = this.queueListingElement.currentItem
+
     recursivelyUnqueueTracks(topItem)
     this.queueListingElement.buildItems()
+
+    if (focusItem) {
+      this.queueListingElement.selectAndShow(focusItem)
+    }
   }
 
   async downloadGrouplikeItem(item) {
@@ -1127,9 +1145,8 @@ class GrouplikeListingElement extends Form {
 
     if (wasSelected) {
       if (resetIndex) {
-        form.curIndex = form.firstItemIndex
         form.scrollItems = 0
-        form.updateSelectedElement()
+        form.selectInput(form.firstItemIndex)
       } else {
         this.root.select(form)
       }
@@ -1171,7 +1188,7 @@ class GrouplikeListingElement extends Form {
   }
 
   selectAndShow(item) {
-    this.form.selectAndShow(item)
+    return this.form.selectAndShow(item)
   }
 
   handleJumpValue(value, isConfirm) {
@@ -1292,7 +1309,9 @@ class GrouplikeListingForm extends ListScrollForm {
         this.updateSelectedElement()
       }
       this.scrollSelectedElementIntoView()
+      return true
     }
+    return false
   }
 }