           @lastUI.setKeywords @keywords
         when "completions"
           # The result objects coming from the background page will be of the form:
-          #   { html: "", type: "", url: "" }
+          #   { html: "", type: "", url: "", ... }
           # Type will be one of [tab, bookmark, history, domain, search], or a custom search engine description.
           for result in msg.results
-            result.performAction =
-              if result.type == "tab"
-                @completionActions.switchToTab.curry result.tabId
-              else
-                @completionActions.navigateToUrl.curry result.url
-
-          # Cache the result -- if we have been told it's ok to do so (it could be that more results will be
-          # posted shortly).  We cache the result even if it arrives late.
+            extend result,
+              performAction:
+                if result.type == "tab"
+                  @completionActions.switchToTab result.tabId
+                else
+                  @completionActions.navigateToUrl result.url
+
+          # Cache the results, but only if we have been told it's ok to do so (it could be that more results
+          # will be posted shortly).  We cache the results even if they arrive late.
           if msg.mayCacheResults
             console.log "cache set:", "-#{msg.cacheKey}-" if @debug
             @cache[msg.cacheKey] = msg

        cacheKey: cacheKey

  reset: ->
    @keywords = []
    @cache = {}

  refresh: (@lastUI) ->
    @reset()
    # Inform the background completer that we have a new vomnibar activation.
    @port.postMessage name: @name, handler: "refresh"

  cancel: ->
    # Inform the background completer that it may (should it choose to do so) abandon any pending query
    # (because the user is typing, and there'll be another query along soon).
    @port.postMessage name: @name, handler: "cancel"

  # These are the actions we can perform when the user selects a result.
  completionActions:
    navigateToUrl: (url, openInNewTab) ->
      # If the URL is a bookmarklet (so, prefixed with "javascript:"), then we always open it in the current
      # tab.
      openInNewTab &&= not Utils.hasJavascriptPrefix url

  inputContainsASelectionRange: ->
    @input.selectionStart? and @input.selectionEnd? and @input.selectionStart != @input.selectionEnd

  # Return the text of the input, with any selected text removed.
  getInputWithoutSelectionRange: ->
    if @inputContainsASelectionRange()
      @input.value[0...@input.selectionStart] + @input.value[@input.selectionEnd..]
