From 59bcb270798edcd53ad9b97a881bde2b58b38522 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 5 Mar 2012 17:29:12 -0700 Subject: [PATCH] WIP: Start handling nested folds. --- spec/atom/renderer-spec.coffee | 15 +++++++++++- src/atom/line-map.coffee | 2 ++ src/atom/renderer.coffee | 45 ++++++++++++++++++++-------------- 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/spec/atom/renderer-spec.coffee b/spec/atom/renderer-spec.coffee index 943316d9b..2744b86d0 100644 --- a/spec/atom/renderer-spec.coffee +++ b/spec/atom/renderer-spec.coffee @@ -96,8 +96,21 @@ fdescribe "Renderer", -> expect(event.oldRange).toEqual [[2, 0], [2, 26]] changeHandler.reset() - describe "when a fold is nested within another fold", -> + it "only renders the placeholder for the inner fold when the outer fold is destroyed", -> + outerFold = renderer.createFold([[4, 29], [8, 36]]) + innerFold = renderer.createFold([[8, 5], [8, 10]]) + + [line4, line5] = renderer.linesForRows(4, 5) + expect(line4.text).toBe ' while(items.length > 0) {...concat(sort(right));' + expect(line5.text).toBe ' };' + + outerFold.destroy() + + [line4, line5] = renderer.linesForRows(4, 5) + expect(line4.text).toBe ' while(items.length > 0) {' + expect(line5.text).toBe ' current = items.shift();' + expect(renderer.lineForRow(8).text).toBe ' r... sort(left).concat(pivot).concat(sort(right));' describe "when a fold begins on the line on which another fold ends", -> diff --git a/src/atom/line-map.coffee b/src/atom/line-map.coffee index 0ad0c9a84..276d7d08d 100644 --- a/src/atom/line-map.coffee +++ b/src/atom/line-map.coffee @@ -108,6 +108,8 @@ class LineMap lastLineFragment = traversalResult.lastLineFragment sourceDelta = traversalResult[sourceDeltaType] targetDelta = traversalResult[targetDeltaType] + + return targetDelta unless lastLineFragment maxSourceColumn = sourceDelta.column + lastLineFragment.text.length maxTargetColumn = targetDelta.column + lastLineFragment.text.length diff --git a/src/atom/renderer.coffee b/src/atom/renderer.coffee index 7540b92e7..0cd8b68d2 100644 --- a/src/atom/renderer.coffee +++ b/src/atom/renderer.coffee @@ -71,6 +71,9 @@ class Renderer screenRowForBufferRow: (bufferRow) -> @lineMap.outputPositionForInputPosition([bufferRow, 0]).row + bufferRowForScreenRow: (screenRow) -> + @lineMap.inputPositionForOutputPosition([screenRow, 0]).row + screenRangeForBufferRange: (bufferRange) -> @lineMap.outputRangeForInputRange(bufferRange) @@ -80,28 +83,34 @@ class Renderer buildLineForBufferRow: (bufferRow) -> @buildLinesForBufferRows(bufferRow, bufferRow) - buildLinesForBufferRows: (startRow, endRow, startColumn) -> - return [] if startRow > endRow and not startColumn? + buildLinesForBufferRows: (startRow, endRow) -> + buildLinesForBufferRows = (startRow, endRow, startColumn) => + return [] if startRow > endRow and not startColumn? - startColumn ?= 0 - line = @highlighter.lineForRow(startRow).splitAt(startColumn)[1] + startColumn ?= 0 + line = @highlighter.lineForRow(startRow).splitAt(startColumn)[1] - wrapColumn = @findWrapColumn(line.text) + wrapColumn = @findWrapColumn(line.text) - for fold in @foldsForBufferRow(startRow) - if fold.start.column >= startColumn - break if fold.start.column > wrapColumn - foldPlaceholderLength - prefix = line.splitAt(fold.start.column - startColumn)[0] - placeholder = @buildFoldPlaceholder(fold) - suffix = @buildLinesForBufferRows(fold.end.row, endRow, fold.end.column) - return _.compact _.flatten [prefix, placeholder, suffix] + for fold in @foldsForBufferRow(startRow) + if fold.start.column >= startColumn + break if fold.start.column > wrapColumn - foldPlaceholderLength + prefix = line.splitAt(fold.start.column - startColumn)[0] + placeholder = @buildFoldPlaceholder(fold) + suffix = buildLinesForBufferRows(fold.end.row, endRow, fold.end.column) + return _.compact _.flatten [prefix, placeholder, suffix] - if wrapColumn - line = line.splitAt(wrapColumn)[0] - line.outputDelta = new Point(1, 0) - [line].concat @buildLinesForBufferRows(startRow, endRow, startColumn + wrapColumn) - else - [line].concat @buildLinesForBufferRows(startRow + 1, endRow) + if wrapColumn + line = line.splitAt(wrapColumn)[0] + line.outputDelta = new Point(1, 0) + [line].concat buildLinesForBufferRows(startRow, endRow, startColumn + wrapColumn) + else + [line].concat buildLinesForBufferRows(startRow + 1, endRow) + + buildLinesForBufferRows(@foldStartRowForBufferRow(startRow), endRow) + + foldStartRowForBufferRow: (bufferRow) -> + @bufferRowForScreenRow(@screenRowForBufferRow(bufferRow)) findWrapColumn: (line) -> return unless line.length > @maxLineLength