« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ui.js15
1 files changed, 12 insertions, 3 deletions
diff --git a/ui.js b/ui.js
index 840c7ee..e0ab4f6 100644
--- a/ui.js
+++ b/ui.js
@@ -1821,7 +1821,8 @@ class InlineListPickerElement extends FocusElement {
           label: label,
           action: () => {
             this.curIndex = index
-          }
+          },
+          isDefault: index === this.curIndex
         }))
       })
     } else {
@@ -2919,7 +2920,7 @@ class ContextMenu extends FocusElement {
     this.submenu = null
   }
 
-  show({x = 0, y = 0, items}) {
+  show({x = 0, y = 0, defaultIndex = 0, items}) {
     items = items.filter(Boolean)
     if (!items.length) {
       return
@@ -2951,6 +2952,9 @@ class ContextMenu extends FocusElement {
         addDividerIfWanted()
         this.form.addInput(item.element)
         item.element.showContextMenu = this.showSubmenu
+        if (item.isDefault) {
+          this.root.select(item.element)
+        }
       } else if (item.divider) {
         wantDivider = true
       } else {
@@ -2964,12 +2968,17 @@ class ContextMenu extends FocusElement {
           })
         }
         this.form.addInput(button)
+        if (item.isDefault) {
+          this.root.select(button)
+        }
       }
     }
 
     this.fixLayout()
 
-    this.form.firstInput()
+    if (!items.some(item => item.isDefault)) {
+      this.form.firstInput()
+    }
 
     this.keyboardSelector.reset()
   }