From 6d0e3a0f019e85fd76a92cb015ffcfb0d44a4e07 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 10 May 2015 22:01:39 +0100 Subject: Search completion; alternative vomnibar completion. --- pages/vomnibar.coffee | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'pages') diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee index a52b14b3..5cd2e2f1 100644 --- a/pages/vomnibar.coffee +++ b/pages/vomnibar.coffee @@ -201,13 +201,12 @@ class VomnibarUI # We only highlight matches when the query gets longer (so, not on deletions). return unless previousLength < currentLength - completion = do => + completion = do (completion) => for completion in @completions continue if completion.custonSearchEnginePrimarySuggestion - return completion if completion.custonSearchEngineCompletionSuggestion - return null + return completion if completion.customSearchEngineCompletionSuggestion + null - console.log 1 return unless completion # Fetch the query and suggestion. @@ -215,13 +214,10 @@ class VomnibarUI suggestion = completion.title index = suggestion.toLowerCase().indexOf query - console.log 2 - return unless index <= 1 + return unless 0 <= index suggestion = suggestion[index..] - console.log 3, suggestion return unless query.length < suggestion.length - console.log 4 # If the typed text is all lower case, then make the completion lower case too. suggestion = suggestion.toLowerCase() unless /[A-Z]/.test @getInputWithoutSelectionRange() @@ -263,11 +259,13 @@ class VomnibarUI else if action in [ "tab", "down" ] if action == "tab" if @inputContainsASelectionRange() - # The first tab collapses the selection to the end. - window.getSelection()?.collapseToEnd() - @updateOnInput() + # Tab moves the start of the selection to the end of the current word. + text = @input.value[@input.selectionStart..] + length = text.length + text = text.replace /^\s*\S+/, "" + @input.setSelectionRange @input.selectionStart + (length - text.length), @input.selectionEnd else - # Subsequent tabs behave the same as "down". + # Other tabs behave the same as "down". action = "down" if action == "down" @selection += 1 -- cgit v1.2.3