Make sure moved lines don't go into a fold

This commit is contained in:
Kevin Sawicki 2014-02-11 11:05:10 -08:00
parent 2579f2993b
commit a93bfb5f8c
2 changed files with 27 additions and 2 deletions

View File

@ -2640,6 +2640,24 @@ describe "EditorView", ->
expect(editor.getCursorBufferPosition()).toEqual [9, 0]
expect(buffer.lineForRow(0)).toBe ' var sort = function(items) {'
expect(buffer.lineForRow(9)).toBe 'var quicksort = function () {'
expect(editor.isFoldedAtBufferRow(0)).toBe true
expect(editor.isFoldedAtBufferRow(9)).toBe false
describe "when line below is empty and the line below that is folded", ->
it "moves the line to the empty line", ->
editor.setCursorBufferPosition([0, Infinity])
editor.insertText('\n')
editor.setCursorBufferPosition([0, 0])
editor.foldBufferRow(2)
editorView.trigger 'editor:move-line-down'
expect(editor.getCursorBufferPosition()).toEqual [1, 0]
expect(buffer.lineForRow(0)).toBe ''
expect(buffer.lineForRow(1)).toBe 'var quicksort = function () {'
expect(buffer.lineForRow(2)).toBe ' var sort = function(items) {'
expect(editor.isFoldedAtBufferRow(0)).toBe false
expect(editor.isFoldedAtBufferRow(1)).toBe false
expect(editor.isFoldedAtBufferRow(2)).toBe true
describe "when the cursor is on the last line", ->
it "does not move the line", ->

View File

@ -670,8 +670,9 @@ class Editor extends Model
# Move line around the fold that is directly below the selection
insertDelta = 1
if foldRange = @languageMode.rowRangeForFoldAtBufferRow(selection.end.row + 1)
insertDelta += foldRange[1] - foldRange[0]
if @isFoldedAtBufferRow(selection.end.row + 1)
foldRange = @languageMode.rowRangeForFoldAtBufferRow(selection.end.row + 1)
insertDelta += foldRange[1] - foldRange[0] if foldRange?
for row in rows
screenRow = @screenPositionForBufferPosition([row]).row
@ -694,6 +695,12 @@ class Editor extends Model
insertPosition = Point.min([startRow + insertDelta], @buffer.getEofPosition())
if insertPosition.row is @buffer.getLastRow() and insertPosition.column > 0
lines = "\n#{lines}"
# Make sure the inserted text doesn't go into an existing fold
if @isFoldedAtBufferRow(insertPosition.row)
@destroyFoldsContainingBufferRow(insertPosition.row)
foldedRows.push(insertPosition.row + startRow - endRow + 1)
@buffer.insert(insertPosition, lines)
@foldBufferRow(foldedRow) for foldedRow in foldedRows