   hide: (@postHideCallback = null) ->
     UIComponentServer.postMessage "hide"
     @reset()
+    @completer?.reset()
 
   onHidden: ->
     @postHideCallback?()

class BackgroundCompleter
  debug: true

  # name is background-page completer to connect to: "omni", "tabs", or "bookmarks".
  constructor: (@name) ->
    @port = chrome.runtime.connect name: "completions"
    @messageId = null
    # @keywords and @cache are both reset in @reset().
    # We only cache for the duration of a single vomnibar activation.
    @keywords = []
    @cache = {}
    @reset()

    @port.onMessage.addListener (msg) =>

      @input.value

  # Return the background-page query corresponding to the current input state.  In other words, reinstate any
  # search engine keyword which is currently stripped from the input, and strip any selection.
  getInputValueAsQuery: ->
    (if @suppressedLeadingKeyword? then @suppressedLeadingKeyword + " " else "") + @getInputWithoutSelectionRange()

