WIP: Start handling nested folds.

This commit is contained in:
Nathan Sobo
2012-03-05 17:29:12 -07:00
parent d02817af21
commit 59bcb27079
3 changed files with 43 additions and 19 deletions

View File

@@ -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", ->

View File

@@ -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

View File

@@ -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