Always place cursor at end of selection after inserting text

This commit is contained in:
Nathan Sobo 2012-04-05 17:22:16 -06:00
parent 84ba78c55d
commit 158315ffaa
2 changed files with 8 additions and 1 deletions

View File

@ -1457,10 +1457,16 @@ describe "Editor", ->
describe "when there is a selection", ->
it "replaces the selected text with the typed text", ->
editor.getSelection().setBufferRange(new Range([1, 6], [2, 4]))
editor.setSelectionBufferRange(new Range([1, 6], [2, 4]))
editor.hiddenInput.textInput 'q'
expect(buffer.lineForRow(1)).toBe ' var qif (items.length <= 1) return items;'
it "always places the cursor after the selection", ->
editor.setSelectionBufferRange(new Range([1, 6], [2, 4]), reverse: true)
editor.hiddenInput.textInput 'q'
expect(buffer.lineForRow(1)).toBe ' var qif (items.length <= 1) return items;'
expect(editor.getCursorScreenPosition()).toEqual [1, 7]
describe "when return is pressed", ->
describe "when the cursor is at the beginning of a line", ->
it "inserts an empty line before it", ->

View File

@ -102,6 +102,7 @@ class Selection extends View
{ text, shouldOutdent } = @autoIndentText(text)
@editor.buffer.change(@getBufferRange(), text)
@autoOutdentText() if shouldOutdent
@cursor.setScreenPosition(@getScreenRange().end)
@clearSelection()
autoIndentText: (text) ->