mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Canceling autocomplete restores text and selection, even if selection has changed before cancel
This commit is contained in:
@@ -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', ->
|
||||
|
||||
@@ -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) ->
|
||||
|
||||
Reference in New Issue
Block a user