mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
WIP: Start handling nested folds.
This commit is contained in:
@@ -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", ->
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user