mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Detach buffer change event listeners from Autocomplete when editor's buffer changes
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -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: () ->
|
||||
|
||||
Reference in New Issue
Block a user