   onKeypress: (event) =>
     if @inputContainsASelectionRange()
       # As the user types characters which match a highlighted completion suggestion (in the text input), we
-      # suppress the keyboard event and "simulate" it by advancing the start of the highlighted selection.  We
-      # do this so that the selection doesn't flicker as the user types.
+      # suppress the keyboard event and "simulate" it by advancing the start of the highlighted selection (but
+      # only if the typed character matches).  This avoids flicker as the selection is first collapsed then
+      # replaced.
       if @input.value[@input.selectionStart][0].toLowerCase() == (String.fromCharCode event.charCode).toLowerCase()
         console.log "extend selection:", @getInputWithoutSelectionRange()
         @input.setSelectionRange @input.selectionStart + 1, @input.selectionEnd

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) =>


    completion = suggestions[0].slice query.length, length

    # Don't complete trailing whitespace, strip it.  Then, verify that the completion is still long enough.
    completion = completion.replace /\s+$/, ""
    return unless 0 < completion.length

