« 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--todo.txt3
m---------tui-lib0
-rw-r--r--ui.js12
3 files changed, 15 insertions, 0 deletions
diff --git a/todo.txt b/todo.txt
index ef00c6d..c51c269 100644
--- a/todo.txt
+++ b/todo.txt
@@ -345,6 +345,7 @@ TODO: If you press any key which should select a particular element of the UI
       specific UI parts instead closes the context menu while one is open.
       We already have a key for doing just that (the cancel key, i.e. esc or
       period), so fix this!
+      (Done!)
 
 TODO: g/G should work for navigation in context menus! And probably all
       ListScrollForms, tbh, but I'm kinda weary of introducing new behavior
@@ -374,3 +375,5 @@ TODO: Create a basic Element class, which DisplayElement extends. We have a lot
       of code related to scheduling displaying stuff on the screen, and it'd be
       nice to keep it more separate from all the basic element logic.
       (Done!)
+
+TODO: toString functions for elements! Handy for debugging.
diff --git a/tui-lib b/tui-lib
-Subproject eb3b83fa2d56f3c85ac0d5c9b62223f6bd29794
+Subproject 49eb24099f0a6088976972df5ecb7c927c78a11
diff --git a/ui.js b/ui.js
index b1eb7c4..a3860e9 100644
--- a/ui.js
+++ b/ui.js
@@ -3071,7 +3071,19 @@ class ContextMenu extends FocusElement {
     }
 
     if (this.visible) {
+      const newlySelected = this.root.selectedElement
       this.close()
+
+      // Bad hack: if the menubar is the selected thing, directly select it
+      // (hence setting its previously selected element to whatever we just
+      // restored the selection to as the context menu).
+      const menubar = newlySelected.directAncestors.find(
+        el => el instanceof Menubar)
+      if (menubar) {
+        menubar.select()
+      } else {
+        this.selectedBefore.root.select(newlySelected)
+      }
     }
   }