 class BackgroundCompleter
   # The "name" is the background-page completer to connect to: "omni", "tabs", or "bookmarks".
   constructor: (@name) ->
+
+    # These are the actions we can perform when the user selects a result.
+    @completionActions =
+      navigateToUrl: (url) -> (openInNewTab) ->
+        Vomnibar.getCompleter().launchUrl url, openInNewTab
+      switchToTab: (tabId) -> ->
+        chrome.runtime.sendMessage handler: "selectSpecificTab", id: tabId
+
     @port = chrome.runtime.connect name: "completions"
     @messageId = null
     @reset()

        # Because the the suggestions are updated asynchronously in omni mode, the user may have typed more
        # text than that which is included in the URL associated with the primary suggestion.  Therefore, to
        # avoid a race condition, we construct the query from the actual contents of the input (query).
        query = Utils.createSearchUrl query, @lastReponse.engine.searchUrl if isCustomSearchPrimarySuggestion
        @hide -> Vomnibar.getCompleter().launchUrl query, openInNewTab
      else
        completion = @completions[@selection]
        @hide -> completion.performAction openInNewTab
    else if action == "ctrl-enter"
      # Populate the vomnibar with the current selection's URL.
      if not @customSearchMode? and @selection >= 0
          @previousInputValue ?= @input.value
          @input.value = @completions[@selection]?.url
          @input.scrollLeft = @input.scrollWidth
    else if action == "delete"
      if @customSearchMode? and @input.selectionEnd == 0
        # Normally, with custom search engines, the keyword (e,g, the "w" of "w query terms") is suppressed.
        # If the cursor is at the start of the input, then reinstate the keyword (the "w").
        @input.value = @customSearchMode + @input.value.ltrim()

    if @updateTimer?
      window.clearTimeout @updateTimer
      @updateTimer = null
    return

  shouldActivateCustomSearchMode: ->
    queryTerms = @input.value.ltrim().split /\s+/
