Don't throw exception when confirming autocomplete with no matches

This commit is contained in:
Nathan Sobo
2012-04-20 11:03:25 -06:00
parent 0024cf89de
commit 7b984f3743
2 changed files with 16 additions and 1 deletions

View File

@@ -124,6 +124,21 @@ describe "Autocomplete", ->
expect(editor.getSelection().isEmpty()).toBeTruthy()
expect($(document).find('#autocomplete')).not.toExist()
describe "when there are no matches", ->
it "closes the menu without changing the buffer", ->
editor.buffer.insert([10,0] ,"xxx")
editor.setCursorBufferPosition [10, 3]
autocomplete.attach()
expect(autocomplete.matchesList.find('li').length).toBe 1
expect(autocomplete.matchesList.find('li')).toHaveText ('No matches found')
miniEditor.trigger "autocomplete:confirm"
expect(editor.lineForBufferRow(10)).toBe "xxx"
expect(editor.getCursorBufferPosition()).toEqual [10,3]
expect(editor.getSelection().isEmpty()).toBeTruthy()
expect($(document).find('#autocomplete')).not.toExist()
describe 'autocomplete:cancel event', ->
it 'does not replace selection, removes autocomplete view and returns focus to editor', ->
editor.buffer.insert([10,0] ,"extra:so:extra")

View File

@@ -65,7 +65,7 @@ class Autocomplete extends View
confirm: ->
@editor.getSelection().clearSelection()
@detach()
match = @selectedMatch()
return unless match = @selectedMatch()
position = @editor.getCursorBufferPosition()
@editor.setCursorBufferPosition([position.row, position.column + match.suffix.length])