diff options
| author | Stephen Blott | 2015-05-10 20:49:10 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2015-05-10 20:49:10 +0100 | 
| commit | 447115fdc5eccf0edebd3c24eec9dd7f94a2eae2 (patch) | |
| tree | 3f2d30d8afc1a3c590dcd57026f98ceebd11aba0 /pages | |
| parent | 21895866c43c09caff096ba2ef5503ee220bab73 (diff) | |
| download | vimium-447115fdc5eccf0edebd3c24eec9dd7f94a2eae2.tar.bz2 | |
Search completion; alternative vomnibar completion.
Diffstat (limited to 'pages')
| -rw-r--r-- | pages/vomnibar.coffee | 47 | 
1 files changed, 45 insertions, 2 deletions
diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee index 196ad766..a52b14b3 100644 --- a/pages/vomnibar.coffee +++ b/pages/vomnibar.coffee @@ -116,7 +116,6 @@ class VomnibarUI    # text to the input and selects it. Tab (or just Enter) can then be used to accept the new text, or the user    # can just continue typing.    selectCommonMatches: (response) -> -    #      # Bail if we don't yet have the background completer's final word on the current query.      return unless response.mayCacheResults @@ -187,6 +186,50 @@ class VomnibarUI      @input.value = query + completion      @input.setSelectionRange query.length, query.length + completion.length +  selectFirstSuggestion: (response) -> +    # Bail if we don't yet have the background completer's final word on the current query. +    return unless response.mayCacheResults + +    # Bail if there's an update pending (because then @input and the completion state are out of sync). +    return if @updateTimer? + +    @previousLength ?= @input.value.length +    previousLength = @previousLength +    currentLength = @input.value.length +    @previousLength = currentLength + +    # We only highlight matches when the query gets longer (so, not on deletions). +    return unless previousLength < currentLength + +    completion = do => +      for completion in @completions +        continue if completion.custonSearchEnginePrimarySuggestion +        return completion if completion.custonSearchEngineCompletionSuggestion +        return null + +    console.log 1 +    return unless completion + +    # Fetch the query and suggestion. +    query = @input.value.ltrim().split(/\s+/).join(" ").toLowerCase() +    suggestion = completion.title + +    index = suggestion.toLowerCase().indexOf query +    console.log 2 +    return unless index <= 1 + +    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() + +    suggestion = suggestion[query.length..] +    @input.value = query + suggestion +    @input.setSelectionRange query.length, query.length + suggestion.length +    # Returns the user's action ("up", "down", "tab", "enter", "dismiss", "delete" or null) based on their    # keypress.  We support the arrow keys and various other shortcuts for moving. This method hides that    # complexity. @@ -314,7 +357,7 @@ class VomnibarUI        @selection = Math.min @completions.length - 1, Math.max @initialSelectionValue, @selection        @previousAutoSelect = null if @completions[0]?.autoSelect and @completions[0]?.forceAutoSelect        @updateSelection() -      @selectCommonMatches response +      @selectFirstSuggestion response        callback?()    updateOnInput: =>  | 
