« get me outta code hell

Be safer about avoiding crashes w/ emptying queue while it's selected - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-06-12 21:49:35 -0300
committerFlorrie <towerofnix@gmail.com>2018-06-12 21:49:38 -0300
commitd5680c5f942b29d67a0e9ac10f7eded9b6f6b38c (patch)
tree7e082b2663f12d2fb2b2929cfd39a6f5965074b0
parentd12b06e655e0dd32f751eafdbf031b0b5c0d1409 (diff)
Be safer about avoiding crashes w/ emptying queue while it's selected
E.g. simply clearing the queue (c -- although this didn't cause a crash
because the clear function immediately selects the main queue) or
unqueueing all items (incoming commit).
-rw-r--r--ui.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/ui.js b/ui.js
index 32cbb72..88d3eb0 100644
--- a/ui.js
+++ b/ui.js
@@ -79,6 +79,8 @@ class AppElement extends FocusElement {
       () => this.playGrouplikeItem(item, false)))
     this.queueListingElement.on('shuffle', () => this.shuffleQueue())
     this.queueListingElement.on('clear', () => this.clearQueue())
+    this.queueListingElement.on('select main listing',
+      () => this.form.selectInput(this.grouplikeListingElement))
 
     this.paneRight.addChild(this.queueListingElement.pathElement)
     this.form.addInput(this.queueListingElement.pathElement, false)
@@ -661,6 +663,14 @@ class QueueListingElement extends GrouplikeListingElement {
       return super.keyPressed(keyBuf)
     }
   }
+
+  updateSelectedElement() {
+    if (this.inputs.length) {
+      super.updateSelectedElement()
+    } else {
+      this.emit('select main listing')
+    }
+  }
 }
 
 class PlaybackInfoElement extends DisplayElement {