Autocomplete is cancelled if the mini editor loses focus before a selection is confirmed

This commit is contained in:
Nathan Sobo
2012-05-07 17:31:14 -06:00
parent e60e68b69d
commit 2c8bb91d85
2 changed files with 5 additions and 3 deletions

View File

@@ -307,10 +307,10 @@ describe "Autocomplete", ->
expect(autocomplete.parent()).not.toExist()
expect(editor.lineForBufferRow(10)).toEqual 'pivot '
describe 'when the editor is focused', ->
describe 'when the mini-editor loses focus before the selection is confirmed', ->
it "cancels the autocomplete", ->
editor.attachToDom()
autocomplete.attach()
spyOn(autocomplete, "cancel")
editor.focus()

View File

@@ -82,6 +82,7 @@ class Autocomplete extends View
@wordList = _.unique(@currentBuffer.getText().match(@wordRegex))
confirm: ->
@confirmed = true
@editor.getSelection().clearSelection()
@detach()
return unless match = @selectedMatch()
@@ -94,7 +95,8 @@ class Autocomplete extends View
@editor.setSelectionBufferRange(@originalSelectionBufferRange)
attach: ->
@editor.on 'focus.autocomplete', => @cancel()
@confirmed = false
@miniEditor.on 'focusout', => @cancel() unless @confirmed
@originalSelectedText = @editor.getSelectedText()
@originalSelectionBufferRange = @editor.getSelection().getBufferRange()