       model: fact
       query: @model().query
       selected: key == @state.selectedModelKey
+      ref: key
       onMouseEnter: => @setState selectedModelKey: key
       onMouseLeave: => @setState selectedModelKey: null
       onClick: => @setState selectedModelKey: key; @props.onSelect?()

    else if key < 0 then @model().length - 1
    else key

  moveSelectionUp: ->
    prevKey = if @state.selectedModelKey? then @state.selectedModelKey-1 else -1
    @setState selectedModelKey: @_fixKeyModulo(prevKey)
    # @scrollToCurrent()

  moveSelectionDown: ->
    nextKey = if @state.selectedModelKey? then @state.selectedModelKey+1 else 0
    @setState selectedModelKey: @_fixKeyModulo(nextKey)
    # @scrollToCurrent()

class window.AutoCompleteFactsView extends Backbone.Marionette.Layout
  className: "auto-complete"

  displayName: 'ReactAutoCompleteSearchFactView'

  scrollIntoView: ->
    $el = $(@getDOMNode())
    scrollIntoViewWithinContainer $el, $el.parents('.auto-complete-search-list')

  render: ->
