Detach buffer change event listeners from Autocomplete when editor's buffer changes

This commit is contained in:
Corey Johnson
2012-04-16 15:22:39 -07:00
parent c82ca5d1ee
commit eacb21ca1a
2 changed files with 13 additions and 1 deletions

View File

@@ -81,3 +81,13 @@ describe "Autocomplete", ->
wordList = autocomplete.wordList
expect(wordList).not.toContain "quicksort"
expect(wordList).toContain "Some"
it 'stops listening to previous buffers change events', ->
previousBuffer = editor.buffer
editor.setBuffer new Buffer(require.resolve('fixtures/sample.txt'))
spyOn(autocomplete, "buildWordList")
previousBuffer.change([[0,0],[0,1]], "sauron")
expect(autocomplete.buildWordList).not.toHaveBeenCalled()

View File

@@ -14,8 +14,10 @@ class Autocomplete
@editor.on 'buffer-path-change', => @setCurrentBuffer(@editor.buffer)
setCurrentBuffer: (buffer) ->
@currentBuffer.off '.autocomplete' if @currentBuffer
@currentBuffer = buffer
@currentBuffer.on 'change', => @buildWordList()
@currentBuffer.on 'change.autocomplete', => @buildWordList()
@buildWordList()
buildWordList: () ->