« 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.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/ui.js b/ui.js
index 3d66ce8..b784688 100644
--- a/ui.js
+++ b/ui.js
@@ -971,6 +971,13 @@ export default class AppElement extends FocusElement {
       return
     }
 
+    // If this is the first addition (starting from empty), switch the
+    // remembered context menu page so that the next context menu will show
+    // the marked items automatically.
+    if (!mark.length) {
+      this.itemMenuPage = 'mark'
+    }
+
     for (const track of add) {
       mark.push(track)
     }
@@ -998,6 +1005,15 @@ export default class AppElement extends FocusElement {
       mark.splice(mark.indexOf(track), 1)
     }
 
+    // If this is the last removal (going to empty), switch the remembered
+    // context menu page so that the next context menu will show the usual
+    // controls for the item under the cursor. This isn't exactly necessary
+    // since various fallbacks will handle this value pointing to a page that
+    // doesn't exist anymore, but it's nice for consistency.
+    if (!mark.length) {
+      this.itemMenuPage = 'cursor'
+    }
+
     this.emitMarkChanged()
   }