Canceling autocomplete restores text and selection, even if selection has changed before cancel

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-04-20 17:17:50 -06:00
parent 9d2b005174
commit 11c465b7fd
2 changed files with 7 additions and 2 deletions

View File

@@ -163,6 +163,7 @@ describe "Autocomplete", ->
originalSelectionBufferRange = editor.getSelection().getBufferRange()
autocomplete.attach()
editor.setCursorBufferPosition [0, 0] # even if selection changes before cancel, it should work
miniEditor.trigger "autocomplete:cancel"
expect(editor.lineForBufferRow(10)).toBe "extra:so:extra"
@@ -314,7 +315,9 @@ describe "Autocomplete", ->
autocomplete.attach()
spyOn(autocomplete, "cancel")
editor.focus()
expect(autocomplete.cancel).toHaveBeenCalled()
describe 'when changes are made to the buffer', ->

View File

@@ -90,7 +90,7 @@ class Autocomplete extends View
cancel: ->
@detach()
@editor.getSelection().insertText @originalSelectedText
@editor.buffer.change(@currentMatchBufferRange, @originalSelectedText) if @currentMatchBufferRange
@editor.setSelectionBufferRange(@originalSelectionBufferRange)
attach: ->
@@ -173,7 +173,9 @@ class Autocomplete extends View
startPosition = selection.getBufferRange().start
@isAutocompleting = true
@editor.insertText(match.infix)
@editor.setSelectionBufferRange([startPosition, [startPosition.row, startPosition.column + match.infix.length]])
@currentMatchBufferRange = [startPosition, [startPosition.row, startPosition.column + match.infix.length]]
@editor.setSelectionBufferRange(@currentMatchBufferRange)
@isAutocompleting = false
prefixAndSuffixOfSelection: (selection) ->