« 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.js13
1 files changed, 12 insertions, 1 deletions
diff --git a/ui.js b/ui.js
index c20d319..43c72bc 100644
--- a/ui.js
+++ b/ui.js
@@ -881,6 +881,7 @@ class GrouplikeListingElement extends Form {
     this.addChild(this.jumpElement)
     this.jumpElement.visible = false
     this.oldFocusedIndex = null // To restore to, if a jump is canceled.
+    this.previousJumpValue = '' // To default to, if the user doesn't enter anything.
 
     this.jumpElement.on('cancel', () => this.hideJumpElement(true))
     this.jumpElement.on('change', value => this.handleJumpValue(value, false))
@@ -1046,7 +1047,16 @@ class GrouplikeListingElement extends Form {
   }
 
   handleJumpValue(value, isConfirm) {
-    // Don't perform the search if the user didn't enter anything.
+    // If the user doesn't enter anything, we won't perform a search -- unless
+    // the user just pressed enter. If that's the case, we'll search for
+    // whatever was previously entered into the form. This is to strike a
+    // balance between keeping the jump form simple and unsurprising but also
+    // powerful, i.e. to support easy "repeated" searches (see the below
+    // cmoment about search match prioritization).
+    if (!value.length && isConfirm && this.previousJumpValue) {
+      value = this.previousJumpValue
+    }
+
     if (value.length) {
       // We prioritize searching past the index that the user opened the jump
       // element from (oldFocusedIndex). This is so that it's more practical
@@ -1090,6 +1100,7 @@ class GrouplikeListingElement extends Form {
     }
 
     if (isConfirm) {
+      this.previousJumpValue = value
       this.hideJumpElement()
     }
   }