From 253a637e08365ad5d78215f90ca4c4dcbb6680a8 Mon Sep 17 00:00:00 2001 From: Florrie Date: Tue, 2 Apr 2019 08:13:59 -0300 Subject: 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. --- tui-lib | 2 +- ui.js | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/tui-lib b/tui-lib index aa38d1b..dff1213 160000 --- a/tui-lib +++ b/tui-lib @@ -1 +1 @@ -Subproject commit aa38d1beb78635e5273b89b76c6a2b91428dd62c +Subproject commit dff1213ae0069afcc0aa1b87daa6658732f742b8 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 } } -- cgit 1.3.0-6-gf8a5