« get me outta code hell

save current context menu page number as a named id - 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:42:32 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-14 16:42:32 -0300
commit3111926f8826b323825bde6efe4ffdb3d10488cd (patch)
treec5ea28177952eed3a07b864348de60d653505df2
parenta9cb64751d35334dce978ba2165893eacb4d29bb (diff)
save current context menu page number as a named id
-rw-r--r--ui.js29
1 files changed, 21 insertions, 8 deletions
diff --git a/ui.js b/ui.js
index b786838..20d7381 100644
--- a/ui.js
+++ b/ui.js
@@ -199,7 +199,7 @@ export default class AppElement extends FocusElement {
 
     this.timestampDictionary = new WeakMap()
 
-    this.itemMenuPage = 0
+    this.itemMenuPage = 'cursor'
 
     // We add this is a child later (so that it's on top of every element).
     this.menuLayer = new DisplayElement()
@@ -1429,6 +1429,9 @@ export default class AppElement extends FocusElement {
         })
       }
 
+      // TODO: Implement this! :P
+      // const isMarked = false
+
       // const hasNotesFile = !!getCorrespondingFileForItem(item, '.txt')
       const timestampsItem = this.hasTimestampsFile(item) && (this.timestampsExpanded(item, listing)
         ? {label: 'Collapse saved timestamps', action: () => this.collapseTimestamps(item, listing)}
@@ -1509,23 +1512,33 @@ export default class AppElement extends FocusElement {
       }
     }
 
-    const pages = [
-      this.markGrouplike.items.length && generatePageForItem(this.markGrouplike),
-      el.item && generatePageForItem(el.item)
+    const pageInfo = [
+      this.markGrouplike.items.length && {
+        id: 'mark',
+        page: generatePageForItem(this.markGrouplike),
+      },
+
+      el.item && {
+        id: 'cursor',
+        page: generatePageForItem(el.item),
+      }
     ].filter(Boolean)
 
-    // TODO: Implement this! :P
-    // const isMarked = false
+    const pages = pageInfo.map(({ page }) => page)
+
+    let pageNum = pageInfo.findIndex(({ id }) => id === this.itemMenuPage)
+    if (pageNum === -1) pageNum = pageInfo.findIndex(({ id }) => id === 'cursor')
+    if (pageNum === -1) pageNum = 0
 
     const menu = this.showContextMenu({
       x: el.absLeft,
       y: el.absTop + 1,
       pages,
-      pageNum: this.itemMenuPage
+      pageNum,
     })
 
     menu.on('page changed', pageNum => {
-      this.itemMenuPage = pageNum
+      this.itemMenuPage = pageInfo[pageNum].id
     })
   }