When DisplayBuffer.foldBufferRow is called with a buffer row that is within a fold, it folds the scope that incloses the buffer row's fold

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-07-30 11:33:15 -07:00
parent 9622d6f9b3
commit a7db67e68d
2 changed files with 13 additions and 8 deletions

View File

@@ -194,6 +194,15 @@ describe "DisplayBuffer", ->
expect(fold.startRow).toBe 1
expect(fold.endRow).toBe 9
describe "when the bufferRow is already folded", ->
it "searches upward for the first row that begins a syntatic region containing the folded row (and folds it)", ->
displayBuffer.foldBufferRow(2)
expect(displayBuffer.lineForRow(1).fold).toBeDefined()
expect(displayBuffer.lineForRow(0).fold).not.toBeDefined()
displayBuffer.foldBufferRow(1)
expect(displayBuffer.lineForRow(0).fold).toBeDefined()
describe ".unfoldBufferRow(bufferRow)", ->
describe "when bufferRow can be unfolded", ->
it "destroys a fold based on the syntactic region starting at the given row", ->

View File

@@ -61,18 +61,14 @@ class DisplayBuffer
[startRow, endRow] = @tokenizedBuffer.rowRangeForFoldAtBufferRow(currentRow) ? []
continue unless startRow? and startRow <= bufferRow <= endRow
fold = @largestFoldStartingAtBufferRow(startRow)
@createFold(startRow, endRow) unless fold
continue if fold
@createFold(startRow, endRow)
return
unfoldBufferRow: (bufferRow) ->
for currentRow in [bufferRow..0]
[startRow, endRow] = @tokenizedBuffer.rowRangeForFoldAtBufferRow(currentRow) ? []
continue unless startRow? and startRow <= bufferRow <= endRow
fold = @largestFoldStartingAtBufferRow(startRow)
fold.destroy() if fold
return
@largestFoldContainingBufferRow(bufferRow)?.destroy()
createFold: (startRow, endRow) ->
return fold if fold = @foldFor(startRow, endRow)