Add move-down event to Autocomplete

This commit is contained in:
Corey Johnson
2012-04-17 17:30:31 -07:00
parent f8fd7251e4
commit 904c05660d
2 changed files with 24 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ class Autocomplete extends View
initialize: (@editor) ->
requireStylesheet 'autocomplete.css'
@on 'autocomplete:toggle', => @toggle()
@on 'move-up', => @previousMatch()
@on 'move-down', => @nextMatch()
@editor.on 'buffer-path-change', => @setCurrentBuffer(@editor.buffer)
@@ -45,6 +46,11 @@ class Autocomplete extends View
@css {left: left, top: top + @editor.lineHeight}
$(document.body).append(this)
previousMatch: ->
previousIndex = @currentMatchIndex - 1
previousIndex = @matches.length - 1 if previousIndex < 0
@selectMatch(previousIndex)
nextMatch: ->
nextIndex = (@currentMatchIndex + 1) % @matches.length
@selectMatch(nextIndex)