Don't move trailing newline for multiline selections

This commit is contained in:
Kevin Sawicki
2013-01-29 16:09:55 -08:00
parent 4bfa5dd7a0
commit 1303e58a87
2 changed files with 26 additions and 2 deletions

View File

@@ -2351,6 +2351,15 @@ describe "Editor", ->
expect(editor.getSelectedBufferRange()).toEqual [[2, 4], [3, 0]]
expect(editor.isFoldedAtScreenRow(3)).toBeTruthy()
describe "when an entire line is selected including the newline", ->
it "moves the selected line up", ->
editor.setCursorBufferPosition([1])
editor.selectToEndOfLine()
editor.selectRight()
editor.trigger 'editor:move-line-up'
expect(buffer.lineForRow(0)).toBe ' var sort = function(items) {'
expect(buffer.lineForRow(1)).toBe 'var quicksort = function () {'
describe "when editor:move-line-down is triggered", ->
describe "when there is no selection", ->
it "moves the line where the cursor is down", ->
@@ -2435,3 +2444,12 @@ describe "Editor", ->
expect(buffer.lineForRow(5)).toBe ' while(items.length > 0) {'
expect(editor.getSelectedBufferRange()).toEqual [[4, 4], [5, 0]]
expect(editor.isFoldedAtScreenRow(5)).toBeTruthy()
describe "when an entire line is selected including the newline", ->
it "moves the selected line down", ->
editor.setCursorBufferPosition([1])
editor.selectToEndOfLine()
editor.selectRight()
editor.trigger 'editor:move-line-down'
expect(buffer.lineForRow(1)).toBe ' if (items.length <= 1) return items;'
expect(buffer.lineForRow(2)).toBe ' var sort = function(items) {'

View File

@@ -342,7 +342,10 @@ class EditSession
@transact =>
foldedRows = []
for row in [selection.start.row..selection.end.row]
rows = [selection.start.row..selection.end.row]
if selection.start.row isnt selection.end.row and selection.end.column is 0
rows.pop() unless @isFoldedAtScreenRow(@screenPositionForBufferPosition(selection.end).row)
for row in rows
screenRow = @screenPositionForBufferPosition([row]).row
if @isFoldedAtScreenRow(screenRow)
bufferRange = @bufferRangeForScreenRange([[screenRow], [screenRow + 1]])
@@ -374,7 +377,10 @@ class EditSession
@transact =>
foldedRows = []
for row in [selection.end.row..selection.start.row]
rows = [selection.end.row..selection.start.row]
if selection.start.row isnt selection.end.row and selection.end.column is 0
rows.shift() unless @isFoldedAtScreenRow(@screenPositionForBufferPosition(selection.end).row)
for row in rows
screenRow = @screenPositionForBufferPosition([row]).row
if @isFoldedAtScreenRow(screenRow)
bufferRange = @bufferRangeForScreenRange([[screenRow], [screenRow + 1]])