From 52fbd19e24ae5679d9a2cdb7f1fa16b83c40e308 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 10 May 2015 11:40:48 +0100 Subject: Search completion; smooth matched-selection extension. --- pages/vomnibar.coffee | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee index 2077c559..8c655b07 100644 --- a/pages/vomnibar.coffee +++ b/pages/vomnibar.coffee @@ -256,6 +256,16 @@ class VomnibarUI event.preventDefault() true + onKeypress: (event) => + if @inputContainsASelectionRange() + if @input.value[@input.selectionStart][0] == String.fromCharCode event.charCode + console.log "extend selection:", @getInputWithoutSelectionRange() + @input.setSelectionRange @input.selectionStart + 1, @input.selectionEnd + @update() + event.stopImmediatePropagation() + event.preventDefault() + true + # Test whether the input contains selected text. inputContainsASelectionRange: -> @input.selectionStart? and @input.selectionEnd? and @input.selectionStart != @input.selectionEnd @@ -270,7 +280,7 @@ class VomnibarUI # Return the background-page query corresponding to the current input state. In other words, reinstate any # custom search engine keyword which is currently stripped from the input. getInputValueAsQuery: -> - (if @suppressedLeadingKeyword? then @suppressedLeadingKeyword + " " else "") + @input.value + (if @suppressedLeadingKeyword? then @suppressedLeadingKeyword + " " else "") + @getInputWithoutSelectionRange() updateCompletions: (callback = null) -> @completer.filter @getInputValueAsQuery(), (response) => @@ -325,6 +335,7 @@ class VomnibarUI @input = @box.querySelector("input") @input.addEventListener "input", @updateOnInput @input.addEventListener "keydown", @onKeydown + @input.addEventListener "keypress", @onKeypress @completionList = @box.querySelector("ul") @completionList.style.display = "" -- cgit v1.2.3