« get me outta code hell

Escape to exit group - 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-03 15:37:30 -0300
committerFlorrie <towerofnix@gmail.com>2018-06-03 15:37:30 -0300
commitf64bd0252741a749b1f3bc57d79b134ecf42afcb (patch)
treee0924d28b2cc8b8a1454003e23dd7c8514ae1566 /ui.js
parent438f21307cb477361ecd62667860681ed7811bc8 (diff)
Escape to exit group
Diffstat (limited to 'ui.js')
-rw-r--r--ui.js32
1 files changed, 24 insertions, 8 deletions
diff --git a/ui.js b/ui.js
index 5177aed..73442d0 100644
--- a/ui.js
+++ b/ui.js
@@ -312,6 +312,14 @@ class GrouplikeListingElement extends ListScrollForm {
     this.recordStore = recordStore
   }
 
+  keyPressed(keyBuf) {
+    if (telc.isEscape(keyBuf)) {
+      this.loadParentGrouplike()
+    } else {
+      return super.keyPressed(keyBuf)
+    }
+  }
+
   loadGrouplike(grouplike) {
     this.grouplike = grouplike
     this.buildItems(true)
@@ -331,13 +339,7 @@ class GrouplikeListingElement extends ListScrollForm {
     const parent = this.grouplike[parentSymbol]
     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.scrollSelectedElementIntoView()
-      })
+      upButton.on('pressed', () => this.loadParentGrouplike())
       this.addInput(upButton)
     }
 
@@ -367,6 +369,21 @@ class GrouplikeListingElement extends ListScrollForm {
     this.fixLayout()
   }
 
+  loadParentGrouplike() {
+    if (!this.grouplike) {
+      return
+    }
+
+    const parent = this.grouplike[parentSymbol]
+    if (parent) {
+      const oldGrouplike = this.grouplike
+      this.loadGrouplike(parent)
+      this.curIndex = this.inputs.findIndex(inp => inp.item === oldGrouplike) || this.firstItemIndex
+      this.updateSelectedElement()
+      this.scrollSelectedElementIntoView()
+    }
+  }
+
   selectAndShow(item) {
     const index = this.inputs.findIndex(inp => inp.item === item)
     if (index >= 0) {
@@ -385,7 +402,6 @@ class GrouplikeListingElement extends ListScrollForm {
   get isSelected() {
     return this.root.selected && this.root.selected.directAncestors.includes(this)
   }
-
 }
 
 class GrouplikeItemElement extends Button {