« get me outta code hell

Select old group when going out of it - 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>2018-06-01 08:26:23 -0300
committerFlorrie <towerofnix@gmail.com>2018-06-01 08:26:23 -0300
commiteca1367aa1eb83b6ebd32e457903eb8df1d66c99 (patch)
treeafa8ba15d7fcdd3a002a8a8f36a0ae8e0eef5313 /ui.js
parent24466e09fabecb9cc47ed248bb976d32c70ab3e4 (diff)
Select old group when going out of it
Diffstat (limited to 'ui.js')
-rw-r--r--ui.js9
1 files changed, 8 insertions, 1 deletions
diff --git a/ui.js b/ui.js
index 7a3a333..3d65d27 100644
--- a/ui.js
+++ b/ui.js
@@ -256,7 +256,10 @@ class GrouplikeListingElement extends ListScrollForm {
     if (parent) {
       const upButton = new Button('Up (to ' + (parent.name || 'unnamed group') + ')')
       upButton.on('pressed', () => {
+        const oldGrouplike = this.grouplike
         this.loadGrouplike(parent)
+        this.curIndex = this.inputs.findIndex(inp => inp.item === oldGrouplike) || this.firstItemIndex
+        this.updateSelectedElement()
       })
       this.addInput(upButton)
     }
@@ -275,7 +278,7 @@ class GrouplikeListingElement extends ListScrollForm {
 
     if (wasSelected) {
       if (resetIndex) {
-        this.curIndex = Math.min(this.inputs.length, 1)
+        this.curIndex = this.firstItemIndex
         this.scrollItems = 0
         this.updateSelectedElement()
       } else {
@@ -285,6 +288,10 @@ class GrouplikeListingElement extends ListScrollForm {
 
     this.fixLayout()
   }
+
+  get firstItemIndex() {
+    return Math.min(this.inputs.length, 1)
+  }
 }
 
 class GrouplikeItemElement extends Button {