Select the replaced text post replacement.

This commit is contained in:
Amy Troschinetz 2016-05-20 17:52:14 -05:00 committed by lexicalunit
parent 82c49001f4
commit ac7bb27e22
2 changed files with 11 additions and 5 deletions

View File

@ -4868,8 +4868,8 @@ describe "TextEditor", ->
editor.replaceSelectedText {}, -> '123'
expect(buffer.lineForRow(0)).toBe '123var quicksort = function () {'
editor.replaceSelectedText {selectWordIfEmpty: true}, -> 'var'
editor.setCursorBufferPosition([0])
editor.replaceSelectedText {selectWordIfEmpty: true}, -> 'var'
expect(buffer.lineForRow(0)).toBe 'var quicksort = function () {'
editor.setCursorBufferPosition([10])
@ -4882,6 +4882,12 @@ describe "TextEditor", ->
editor.replaceSelectedText {}, -> 'ia'
expect(buffer.lineForRow(0)).toBe 'via quicksort = function () {'
it "replaces the selected text and selects the replacement text", ->
editor.setSelectedBufferRange([[0, 4], [0, 9]])
editor.replaceSelectedText {}, -> 'whatnot'
expect(buffer.lineForRow(0)).toBe 'var whatnotsort = function () {'
expect(editor.getSelectedBufferRange()).toEqual [[0, 4], [0, 11]]
describe ".transpose()", ->
it "swaps two characters", ->
editor.buffer.setText("abc")
@ -4902,7 +4908,7 @@ describe "TextEditor", ->
editor.setCursorScreenPosition([0, 1])
editor.upperCase()
expect(editor.lineTextForBufferRow(0)).toBe 'ABC'
expect(editor.getSelectedBufferRange()).toEqual [[0, 1], [0, 1]]
expect(editor.getSelectedBufferRange()).toEqual [[0, 0], [0, 3]]
describe "when there is a selection", ->
it "upper cases the current selection", ->
@ -4919,7 +4925,7 @@ describe "TextEditor", ->
editor.setCursorScreenPosition([0, 1])
editor.lowerCase()
expect(editor.lineTextForBufferRow(0)).toBe 'abc'
expect(editor.getSelectedBufferRange()).toEqual [[0, 1], [0, 1]]
expect(editor.getSelectedBufferRange()).toEqual [[0, 0], [0, 3]]
describe "when there is a selection", ->
it "lower cases the current selection", ->

View File

@ -1328,12 +1328,12 @@ class TextEditor extends Model
replaceSelectedText: (options={}, fn) ->
{selectWordIfEmpty} = options
@mutateSelectedText (selection) ->
range = selection.getBufferRange()
selection.getBufferRange()
if selectWordIfEmpty and selection.isEmpty()
selection.selectWord()
text = selection.getText()
selection.deleteSelectedText()
selection.insertText(fn(text))
range = selection.insertText(fn(text))
selection.setBufferRange(range)
# Split multi-line selections into one selection per line.