« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--todo.txt1
-rw-r--r--ui.js15
2 files changed, 11 insertions, 5 deletions
diff --git a/todo.txt b/todo.txt
index b210799..18ed0c9 100644
--- a/todo.txt
+++ b/todo.txt
@@ -538,6 +538,7 @@ TODO: Selecting a group from the path listing at the bottom of listings should
       For example: selecting X in W/X/Y/Z would open the directory X and
       select item Y; selecting Z would open the directory Z and select the
       track (or group) which the path element is active on in the first place.
+      (Done!)
 
 TODO: UI to change the directory from which mtui reads music by default!
 
diff --git a/ui.js b/ui.js
index ae3cf32..85cefcd 100644
--- a/ui.js
+++ b/ui.js
@@ -737,7 +737,7 @@ class AppElement extends FocusElement {
     // Sets up event listeners that are common to ordinary grouplike listings
     // (made by newGrouplikeListing) as well as the queue grouplike listing.
 
-    grouplikeListing.pathElement.on('select', item => this.reveal(item))
+    grouplikeListing.pathElement.on('select', (item, child) => this.reveal(item, child))
     grouplikeListing.on('menu', (item, el) => this.showMenuForItemElement(el, grouplikeListing))
     /*
     grouplikeListing.on('select', item => this.editNotesFile(item, false))
@@ -758,7 +758,7 @@ class AppElement extends FocusElement {
     return menu
   }
 
-  reveal(item) {
+  reveal(item, child) {
     if (!this.tabberPane.visible) {
       return
     }
@@ -769,6 +769,9 @@ class AppElement extends FocusElement {
     const parent = item[parentSymbol]
     if (isGroup(item)) {
       tabberListing.loadGrouplike(item)
+      if (child) {
+        tabberListing.selectAndShow(child)
+      }
     } else if (parent) {
       if (tabberListing.grouplike !== parent) {
         tabberListing.loadGrouplike(parent)
@@ -3080,10 +3083,12 @@ class PathElement extends ListScrollForm {
     const itemPath = getItemPath(item)
     const parentPath = itemPath.slice(0, -1)
 
-    for (const pathItem of parentPath) {
-      const isFirst = pathItem === parentPath[0]
+    for (let i = 0; i < parentPath.length; i++) {
+      const pathItem = parentPath[i]
+      const nextItem = itemPath[i + 1]
+      const isFirst = (i === 0)
       const element = new PathItemElement(pathItem, isFirst)
-      element.on('select', () => this.emit('select', pathItem))
+      element.on('select', () => this.emit('select', pathItem, nextItem))
       element.fixLayout()
       this.addInput(element)
     }