Autocomplete uses attach/detach

This commit is contained in:
Corey Johnson
2012-04-18 11:35:58 -07:00
parent 6b63d8eb8d
commit 376b9c4217

View File

@@ -49,12 +49,13 @@ class Autocomplete extends View
cancel: ->
@editor.getSelection().insertText @originalSelectedText
@editor.setSelectionBufferRange(@originalSelectionBufferRange)
@remove()
@detach()
toggle: ->
if @parent()[0] then @remove() else @show()
if @parent()[0] then @detach() else @attach()
show: ->
attach: ->
@editor.addClass('autocomplete')
@originalSelectedText = @editor.getSelectedText()
@originalSelectionBufferRange = @editor.getSelection().getBufferRange()
@buildMatchList()
@@ -66,6 +67,10 @@ class Autocomplete extends View
$(document.body).append(this)
@focus()
detach: ->
@editor.removeClass('autocomplete')
super
previousMatch: ->
previousIndex = @currentMatchIndex - 1
previousIndex = @matches.length - 1 if previousIndex < 0
@@ -90,7 +95,7 @@ class Autocomplete extends View
select: ->
@editor.getSelection().clearSelection()
@remove()
@detach()
@editor.focus()
buildWordList: () ->