« get me outta code hell

remember which main context menu page was open - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-05-14 16:35:00 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-14 16:35:00 -0300
commita9cb64751d35334dce978ba2165893eacb4d29bb (patch)
tree6d0c0b5aa07991bf289677b88505f1553f1da84d
parent1b3584f7f658d3df61ae2c5711280236490dc55d (diff)
remember which main context menu page was open
-rw-r--r--ui.js15
1 files changed, 12 insertions, 3 deletions
diff --git a/ui.js b/ui.js
index 3e0098f..b786838 100644
--- a/ui.js
+++ b/ui.js
@@ -199,6 +199,8 @@ export default class AppElement extends FocusElement {
 
     this.timestampDictionary = new WeakMap()
 
+    this.itemMenuPage = 0
+
     // We add this is a child later (so that it's on top of every element).
     this.menuLayer = new DisplayElement()
     this.menuLayer.clickThrough = true
@@ -1515,10 +1517,15 @@ export default class AppElement extends FocusElement {
     // TODO: Implement this! :P
     // const isMarked = false
 
-    this.showContextMenu({
+    const menu = this.showContextMenu({
       x: el.absLeft,
       y: el.absTop + 1,
-      pages
+      pages,
+      pageNum: this.itemMenuPage
+    })
+
+    menu.on('page changed', pageNum => {
+      this.itemMenuPage = pageNum
     })
   }
 
@@ -4837,6 +4844,7 @@ class ContextMenu extends FocusElement {
         }
         this.close(false)
         this.show({x, y, pages, pageNum})
+        this.emit('page changed', pageNum)
       }
     }
 
@@ -4848,6 +4856,7 @@ class ContextMenu extends FocusElement {
         }
         this.close(false)
         this.show({x, y, pages, pageNum})
+        this.emit('page changed', pageNum)
       }
     }
 
@@ -4859,7 +4868,7 @@ class ContextMenu extends FocusElement {
       if (pages.length === 0) {
         return
       }
-      itemsArg = pages[pageNum]
+      itemsArg = pages[Math.min(pages.length - 1, pageNum)]
     }
 
     let items = (typeof itemsArg === 'function') ? itemsArg() : itemsArg