diff options
author | Florrie <towerofnix@gmail.com> | 2018-12-28 20:05:41 -0400 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-12-28 20:05:41 -0400 |
commit | 0d0a8ab505f670cb0df3bf403b919c55463d9a1c (patch) | |
tree | 61f24aa5dfef90292d227557c76ae2fcb59097d5 | |
parent | a2cc42234b93ba08bf19173b07420f7a42d74d89 (diff) |
Automatically use previous input if empty in '/'
If you press enter in the JumpElement form while it's still empty, automatically treat the previously-entered input as the entered value, so that it's easy to quickly do a "repeated" search (you don't have to enter the same value over and over again).
-rw-r--r-- | ui.js | 13 |
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() } } |