From c491d9243738a9af23aae78881bbd9cd2eafab05 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 18 May 2012 20:14:05 -0600 Subject: [PATCH] Nested folds can start at the same row as the fold that contains them ...still need to test destroying the outer fold though. --- spec/app/renderer-spec.coffee | 14 ++++++++++---- src/app/renderer.coffee | 7 ++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/spec/app/renderer-spec.coffee b/spec/app/renderer-spec.coffee index 2a92a3a1a..b5e072541 100644 --- a/spec/app/renderer-spec.coffee +++ b/spec/app/renderer-spec.coffee @@ -316,10 +316,16 @@ describe "Renderer", -> expect(line6.screenDelta).toEqual [1, 0] expect(line7.text).toBe '8' - it "allows the outer fold to start at the same location as the inner fold", -> - renderer.createFold([[4, 29], [7, 4]]) - renderer.createFold([[4, 29], [9, 2]]) - expect(renderer.lineForRow(4).text).toBe " while(items.length > 0) {...};" + fit "allows the outer fold to start at the same location as the inner fold", -> + innerFold = renderer.createFold(4, 6) + outerFold = renderer.createFold(4, 8) + + [line4, line5] = renderer.linesForRows(4, 5) + expect(line4.fold).toBe outerFold + expect(line4.text).toMatch /4-+/ + expect(line4.bufferDelta).toEqual [5, 0] + expect(line4.screenDelta).toEqual [1, 0] + expect(line5.text).toMatch /9-+/ describe "when a fold begins on the line on which another fold ends", -> describe "when the second fold is created before the first fold", -> diff --git a/src/app/renderer.coffee b/src/app/renderer.coffee index c1a942165..c49fe5d23 100644 --- a/src/app/renderer.coffee +++ b/src/app/renderer.coffee @@ -137,7 +137,7 @@ class Renderer while startBufferRow <= endBufferRow screenLine = @highlighter.lineForRow(startBufferRow) - if fold = @foldForBufferRow(startBufferRow) + if fold = @largestFoldForBufferRow(startBufferRow) screenLine = screenLine.copy() screenLine.fold = fold screenLine.bufferDelta = fold.getBufferDelta() @@ -184,8 +184,9 @@ class Renderer _.remove(folds, fold) delete @foldsById[fold.id] - foldForBufferRow: (bufferRow) -> - @activeFolds[bufferRow]?[0] + largestFoldForBufferRow: (bufferRow) -> + return unless folds = @activeFolds[bufferRow] + (folds.sort (a, b) -> b.endRow - a.endRow)[0] buildFoldPlaceholder: (fold) ->