 
   initialize: (@editor) ->
     requireStylesheet 'autocomplete.css'
-    @on 'autocomplete:toggle', => @toggle()
+    @editor.on 'autocomplete:toggle', => @toggle()
     @on 'move-up', => @previousMatch()
     @on 'move-down', => @nextMatch()
     @editor.on 'buffer-path-change', => @setCurrentBuffer(@editor.buffer)

    {left, top} = @editor.pixelOffsetForScreenPosition(cursorScreenPosition)
    @css {left: left, top: top + @editor.lineHeight}
    $(document.body).append(this)

  previousMatch: ->
    previousIndex = @currentMatchIndex - 1

module.exports =
class Autocomplete extends View
  @content: ->
    @div id: 'autocomplete', tabindex: -1, =>
      @ol outlet: 'matchesList'

  editor: null
