diff options
| -rw-r--r-- | background_scripts/completion.coffee | 2 | ||||
| -rw-r--r-- | pages/vomnibar.coffee | 47 | 
2 files changed, 47 insertions, 2 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index d0058538..e09d01ef 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -449,6 +449,7 @@ class SearchEngineCompleter          # We suppress the leading keyword, for example "w something" becomes "something" in the vomnibar.          suppressLeadingKeyword: true          selectCommonMatches: false +        custonSearchEnginePrimarySuggestion: true          # Toggles for the legacy behaviour.          autoSelect: not useExclusiveVomnibar          forceAutoSelect: not useExclusiveVomnibar @@ -465,6 +466,7 @@ class SearchEngineCompleter            insertText: suggestion            highlightTerms: false            selectCommonMatches: true +          custonSearchEngineCompletionSuggestion: true      # If we have cached suggestions, then we can bundle them immediately (otherwise we'll have to fetch them      # asynchronously). 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: =>  | 
