From 0d0a8ab505f670cb0df3bf403b919c55463d9a1c Mon Sep 17 00:00:00 2001 From: Florrie Date: Fri, 28 Dec 2018 20:05:41 -0400 Subject: 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). --- ui.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'ui.js') 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() } } -- cgit 1.3.0-6-gf8a5