Deleting before fold no longer unfolds after undo

Use same row delta computation for updating start and
end rows in folds.
This commit is contained in:
Corey Johnson & Kevin Sawicki 2013-01-30 09:08:12 -08:00
parent a2b1f33518
commit 4db876aed1
2 changed files with 22 additions and 22 deletions

View File

@ -495,6 +495,20 @@ describe "DisplayBuffer", ->
expect(displayBuffer.lineForRow(8).text).toMatch /^9-+/
expect(displayBuffer.lineForRow(10).fold).toBeDefined()
describe "when the line being deleted preceeds a fold", ->
describe "when the command is undone", ->
it "restores the line and preserves the fold", ->
editSession.setCursorBufferPosition([4])
editSession.foldCurrentRow()
expect(editSession.isFoldedAtScreenRow(4)).toBeTruthy()
editSession.setCursorBufferPosition([3])
editSession.deleteLine()
expect(editSession.isFoldedAtScreenRow(3)).toBeTruthy()
expect(buffer.lineForRow(3)).toBe ' while(items.length > 0) {'
editSession.undo()
expect(editSession.isFoldedAtScreenRow(4)).toBeTruthy()
expect(buffer.lineForRow(3)).toBe ' var pivot = items.shift(), current, left = [], right = [];'
describe ".clipScreenPosition(screenPosition, wrapBeyondNewlines: false, wrapAtSoftNewlines: false, skipAtomicTokens: false)", ->
beforeEach ->
displayBuffer.setSoftWrapColumn(50)

View File

@ -36,8 +36,8 @@ class Fold
@displayBuffer.unregisterFold(@startRow, this)
return
@updateStartRow(event)
@updateEndRow(event)
@startRow += @getRowDelta(event, @startRow)
@endRow += @getRowDelta(event, @endRow)
if @startRow != oldStartRow
@displayBuffer.unregisterFold(oldStartRow, this)
@ -49,26 +49,12 @@ class Fold
isContainedByFold: (fold) ->
@isContainedByRange(fold.getBufferRange())
updateStartRow: (event) ->
getRowDelta: (event, row) ->
{ newRange, oldRange } = event
if oldRange.end.row < @startRow
delta = newRange.end.row - oldRange.end.row
else if newRange.end.row < @startRow
delta = newRange.end.row - @startRow
if oldRange.end.row <= row
newRange.end.row - oldRange.end.row
else if newRange.end.row < row
newRange.end.row - row
else
delta = 0
@startRow += delta
updateEndRow: (event) ->
{ newRange, oldRange } = event
if oldRange.end.row <= @endRow
delta = newRange.end.row - oldRange.end.row
else if newRange.end.row <= @endRow
delta = newRange.end.row - @endRow
else
delta = 0
@endRow += delta
0