diff --git a/spec/atom/line-folder-spec.coffee b/spec/atom/line-folder-spec.coffee index 6b82a98bb..1f00690b6 100644 --- a/spec/atom/line-folder-spec.coffee +++ b/spec/atom/line-folder-spec.coffee @@ -95,6 +95,12 @@ describe "LineFolder", -> expect(line4.text).toBe ' while(items.length > 0) {...concat(sort(right));' expect(line5.text).toBe ' };' + it "renders the contents of the outer fold correctly, including the inner fold's placeholder, when the outer fold is destroyed", -> + fold1 = folder.createFold(new Range([4, 29], [7, 4])) + fold2 = folder.createFold(new Range([3, 4], [8, 56])) + fold2.destroy() + expect(folder.lineForScreenRow(5).text).toBe " return sort(left).concat(pivot).concat(sort(right));" + describe "when another fold begins on the last line of a fold", -> describe "when the second fold is created before the first fold", -> it "renders a placeholder for both folds on the first line of the first fold", -> @@ -173,10 +179,10 @@ describe "LineFolder", -> expect(event.oldRange).toEqual [[7, 0], [7, 28]] expect(event.newRange).toEqual [[7, 0], [8, 56]] - describe "when the fold is at the beginning of the line", -> - it "renders a placeholder at the beginning of the line", -> - folder.createFold(new Range([4, 0], [7, 4])) - expect(folder.lineForScreenRow(4).text).toBe '...}' + describe "when the fold starts at the beginning of the line", -> + it "renders a placeholder at the beginning of the line", -> + folder.createFold(new Range([4, 0], [7, 4])) + expect(folder.lineForScreenRow(4).text).toBe '...}' describe "when the buffer changes", -> [fold1, fold2] = [] diff --git a/src/atom/line-folder.coffee b/src/atom/line-folder.coffee index 9e47064b4..1ce8d5a9a 100644 --- a/src/atom/line-folder.coffee +++ b/src/atom/line-folder.coffee @@ -31,7 +31,7 @@ class LineFolder @registerFold(bufferRange.start.row, fold) oldScreenRange = @expandScreenRangeToLineEnds(@screenRangeForBufferRange(bufferRange)) - lineWithFold = @buildLine(oldScreenRange.start.row) + lineWithFold = @buildLineForBufferRow(bufferRange.start.row) @lineMap.replaceScreenRows(oldScreenRange.start.row, oldScreenRange.end.row, lineWithFold) newScreenRange = oldScreenRange.copy() @@ -86,25 +86,28 @@ class LineFolder unless oldScreenRange.isEmpty() and newScreenRange.isEmpty() @trigger 'change', oldRange: expandedOldScreenRange, newRange: expandedNewScreenRange - buildLinesForBufferRows: (start, end) -> - lines = [@buildLine(@screenRowForBufferRow(start))] - if end > start - for row in [start + 1..end] - lines.push @buildLineForBufferRow(row) - _.flatten(lines) + buildLineForBufferRow: (bufferRow) -> + @buildLinesForBufferRows(bufferRow, bufferRow) - buildLine: (screenRow) -> - @buildLineForBufferRow(@bufferRowForScreenRow(screenRow)) + buildLinesForBufferRows: (startRow, endRow) -> + @$buildLinesForBufferRows(@foldStartRowForBufferRow(startRow), endRow) - buildLineForBufferRow: (bufferRow, startColumn=0) -> - screenLine = @highlighter.lineForScreenRow(bufferRow).splitAt(startColumn)[1] - for fold in @foldsForBufferRow(bufferRow) + $buildLinesForBufferRows: (startRow, endRow, startColumn = 0) -> + return [] if startRow > endRow and startColumn == 0 + + screenLine = @highlighter.lineForScreenRow(startRow).splitAt(startColumn)[1] + + for fold in @foldsForBufferRow(startRow) { start, end } = fold.getRange() if start.column >= startColumn prefix = screenLine.splitAt(start.column - startColumn)[0] - suffix = @buildLineForBufferRow(end.row, end.column) + suffix = @$buildLinesForBufferRows(end.row, endRow, end.column) return _.compact(_.flatten([prefix, @buildFoldPlaceholder(fold), suffix])) - screenLine + + [screenLine].concat(@$buildLinesForBufferRows(startRow + 1, endRow)) + + foldStartRowForBufferRow: (bufferRow) -> + @bufferRowForScreenRow(@screenRowForBufferRow(bufferRow)) buildFoldPlaceholder: (fold) -> new ScreenLineFragment([{value: '...', type: 'fold-placeholder', fold}], '...', [0, 3], fold.getRange().toDelta(), isAtomic: true)