« get me outta code hell

clean up some context menu logic to fix reveal bug - 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>2020-05-03 14:49:40 -0300
committerFlorrie <towerofnix@gmail.com>2020-05-03 14:49:40 -0300
commit75b8fdc3aa238f34825cd08faa6906e9b818f47c (patch)
treef04a68c89ce47f22aef1315d17dedb514ccf0ee4
parent359d9d107ed45be9a170e3ecf23f5c39d2eb0588 (diff)
clean up some context menu logic to fix reveal bug
-rw-r--r--todo.txt5
-rw-r--r--ui.js13
2 files changed, 10 insertions, 8 deletions
diff --git a/todo.txt b/todo.txt
index bd75904..c99c70d 100644
--- a/todo.txt
+++ b/todo.txt
@@ -4,10 +4,8 @@ TODO: A way to see the path of the currently selected item in any grouplike
       (Done!)
 
 TODO: A "shuffle queue" button!
-      (Half-way done -- the functionality is there, press "S", but there's no
-      button for it yet.)
-
 TODO: A "clear queue" button.
+      (Done! Press S or C, or choose the option from the menubar.)
 
 TODO: A way to jump to an item with a particular name. Probably press "/".
       It'd be nice if the closest match got highlighted while you were typing.
@@ -509,3 +507,4 @@ TODO: Revisit labels and notes features! They're commented out for now :P
 
 TODO: Pressing "Reveal" should focus the main listing. This is prrrrobably a
       case of context menu selection-restoring being a pain.
+      (Done!)
diff --git a/ui.js b/ui.js
index 5c586dd..0172fc2 100644
--- a/ui.js
+++ b/ui.js
@@ -3751,6 +3751,7 @@ class ContextMenu extends FocusElement {
         button.keyboardIdentifier = item.keyboardIdentifier || item.label
         if (item.action) {
           button.on('pressed', async () => {
+            this.restoreSelection()
             if (await item.action() === 'reload') {
               this.reload()
             } else {
@@ -3797,6 +3798,7 @@ class ContextMenu extends FocusElement {
 
   keyPressed(keyBuf) {
     if (telc.isEscape(keyBuf) || telc.isBackspace(keyBuf)) {
+      this.restoreSelection()
       this.close()
       return false
     } else if (this.keyboardSelector.keyPressed(keyBuf)) {
@@ -3819,24 +3821,25 @@ class ContextMenu extends FocusElement {
     }
 
     if (this.visible) {
-      const newlySelected = this.root.selectedElement
       this.close()
-      newlySelected.root.select(newlySelected)
     }
   }
 
   close(remove = true) {
     this.clearItems()
     this.visible = false
-    if (this.selectedBefore.root.select) {
-      this.selectedBefore.root.select(this.selectedBefore)
-    }
     if (remove && this.parent) {
       this.parent.removeChild(this)
       this.emit('closed')
     }
   }
 
+  restoreSelection() {
+    if (this.selectedBefore.root.select) {
+      this.selectedBefore.root.select(this.selectedBefore)
+    }
+  }
+
   clearItems() {
     // Abhorrent hack - just erases children from memory. Leaves children
     // thinking they've still got a parent, though. (Necessary to avoid crazy