diff --git a/spec/app/autocomplete-spec.coffee b/spec/app/autocomplete-spec.coffee index 38a7b88d1..fd793bd82 100644 --- a/spec/app/autocomplete-spec.coffee +++ b/spec/app/autocomplete-spec.coffee @@ -166,7 +166,19 @@ describe "Autocomplete", -> expect(autocomplete.find('li:eq(0)')).toHaveClass('selected') expect(autocomplete.find('li:eq(1)')).not.toHaveClass('selected') - describe "when the mini-editor receives text input", -> + describe "when the mini-editor's buffer changes", -> + describe "when text is removed from the mini-editor", -> + it "reloads the match list based on the mini-editor's text", -> + editor.buffer.insert([10,0] ,"t") + editor.setCursorBufferPosition([10,0]) + autocomplete.attach() + + expect(autocomplete.matchesList.find('li').length).toBe 8 + miniEditor.textInput('c') + expect(autocomplete.matchesList.find('li').length).toBe 3 + miniEditor.backspace() + expect(autocomplete.matchesList.find('li').length).toBe 8 + describe "when the text contains only word characters", -> it "narrows the list of completions with the fuzzy match algorithm", -> editor.buffer.insert([10,0] ,"t") diff --git a/src/app/autocomplete.coffee b/src/app/autocomplete.coffee index 54921406b..e2839c8f8 100644 --- a/src/app/autocomplete.coffee +++ b/src/app/autocomplete.coffee @@ -37,8 +37,9 @@ class Autocomplete extends View @on 'autocomplete:confirm', => @confirm() @on 'autocomplete:cancel', => @cancel() - @miniEditor.buffer.on 'change', => - @filterMatchList() if @parent()[0] + @miniEditor.buffer.on 'change', (e) => + return unless @parent()[0] + @filterMatchList() @miniEditor.preempt 'move-up', => @selectPreviousMatch() @@ -121,13 +122,14 @@ class Autocomplete extends View if (prefix.length + suffix.length) > 0 currentWord = prefix + @editor.getSelectedText() + suffix - @matches = (match for match in @wordMatches(prefix, suffix) when match.word != currentWord) + @baseMatches = (match for match in @wordMatches(prefix, suffix) when match.word != currentWord) else - @matches = [] - @renderMatchList() + @baseMatches = [] + + @filterMatchList() filterMatchList: -> - @matches = fuzzyFilter(@matches, @miniEditor.buffer.getText(), key: 'word') + @matches = fuzzyFilter(@baseMatches, @miniEditor.getText(), key: 'word') @renderMatchList() renderMatchList: ->