   changeOptions: 'add remove reset sort sync'
 
   getInitialState: ->
-    selectedModelIndex: null
+    hasModelSelected: false
 
   _childView: (fact, index) ->
     ReactFactSearchResult


  _select: (index) ->
    index = @_fixIndexModulo(index)
    @setState selectedModelIndex: index
    @refs[index].scrollIntoView()

  moveSelectionUp: ->
    @_select if @state.selectedModelIndex? then @state.selectedModelIndex-1 else -1

  moveSelectionDown: ->
    @_select if @state.selectedModelIndex? then @state.selectedModelIndex+1 else 0

window.ReactFactSearch = React.createBackboneClass
  displayName: 'ReactFactSearch'

      selected: index == @state.selectedModelIndex
      ref: index
      key: fact.id
      onMouseEnter: => @setState hasModelSelected: true, selectedModelIndex: index
      onMouseLeave: => @setState hasModelSelected: false
      onClick: =>
        @setState hasModelSelected: true, selectedModelIndex: index
        @props.onSelect?()

  selectedModel: ->
    return unless @state.hasModelSelected

    @model().at(@state.selectedModelIndex)

