mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 23:48:05 +03:00
Make sure moved lines don't go into a fold
This commit is contained in:
parent
2579f2993b
commit
a93bfb5f8c
@ -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", ->
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user