mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Folds can be created on the penultimate screen line of a wrapped buffer line
This commit is contained in:
@@ -42,7 +42,7 @@ describe "Renderer", ->
|
||||
expect(renderer.lineForRow(3).text).toBe ' var pivot = items.shift(), current, left = [], '
|
||||
expect(renderer.lineForRow(4).text).toBe 'right = [];'
|
||||
|
||||
describe "when a fold is created on the second screen line of a wrapped buffer line", ->
|
||||
describe "when a fold is created on the last screen line of a wrapped buffer line", ->
|
||||
it "inserts the placeholder in the correct location and fires a change event", ->
|
||||
fold = renderer.createFold([[3, 52], [3, 56]])
|
||||
expect(renderer.lineForRow(3).text).toBe ' var pivot = items.shift(), current, left = [], '
|
||||
@@ -62,6 +62,30 @@ describe "Renderer", ->
|
||||
expect(event.oldRange).toEqual([[3, 0], [4, 10]])
|
||||
expect(event.newRange).toEqual([[3, 0], [4, 11]])
|
||||
|
||||
describe "when a fold is created on the penultimate screen line of a wrapped buffer line", ->
|
||||
beforeEach ->
|
||||
renderer.setMaxLineLength(36)
|
||||
changeHandler.reset()
|
||||
|
||||
it "inserts the placeholder in the correct location and fires a change event", ->
|
||||
fold = renderer.createFold([[6, 29], [6, 33]])
|
||||
expect(renderer.lineForRow(8).text).toBe " current < pivot ? "
|
||||
expect(renderer.lineForRow(9).text).toBe "left....(current) : "
|
||||
expect(renderer.lineForRow(10).text).toBe "right.push(current);"
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[[event]]= changeHandler.argsForCall
|
||||
expect(event.oldRange).toEqual([[8, 0], [10, 20]])
|
||||
expect(event.newRange).toEqual([[8, 0], [10, 20]])
|
||||
|
||||
changeHandler.reset()
|
||||
fold.destroy()
|
||||
|
||||
expect(changeHandler).toHaveBeenCalled()
|
||||
[[event]]= changeHandler.argsForCall
|
||||
expect(event.oldRange).toEqual([[8, 0], [10, 20]])
|
||||
expect(event.newRange).toEqual([[8, 0], [10, 20]])
|
||||
|
||||
describe "when there is a fold placeholder straddling the max length boundary", ->
|
||||
it "wraps the line before the fold placeholder", ->
|
||||
renderer.createFold([[3, 49], [6, 1]])
|
||||
|
||||
@@ -135,7 +135,7 @@ class Renderer
|
||||
@buildLinesForBufferRows(bufferRow, bufferRow)
|
||||
|
||||
buildLinesForBufferRows: (startRow, endRow) ->
|
||||
buildLinesForBufferRows = (startRow, endRow, startColumn, currentScreenLineLength=0) =>
|
||||
recursiveBuildLinesForBufferRows = (startRow, endRow, startColumn, currentScreenLineLength=0) =>
|
||||
return [] if startRow > endRow and not startColumn?
|
||||
|
||||
startColumn ?= 0
|
||||
@@ -145,23 +145,23 @@ class Renderer
|
||||
|
||||
for fold in @foldsForBufferRow(startRow)
|
||||
if fold.start.column >= startColumn
|
||||
if fold.start.column > wrapColumn - foldPlaceholderLength
|
||||
wrapColumn = Math.min(wrapColumn, fold.start.column)
|
||||
if (fold.start.column - startColumn) > wrapColumn - foldPlaceholderLength
|
||||
wrapColumn = Math.min(wrapColumn, fold.start.column - startColumn)
|
||||
break
|
||||
prefix = line.splitAt(fold.start.column - startColumn)[0]
|
||||
placeholder = @buildFoldPlaceholder(fold)
|
||||
currentScreenLineLength = currentScreenLineLength + (prefix?.text.length ? 0) + foldPlaceholderLength
|
||||
suffix = buildLinesForBufferRows(fold.end.row, endRow, fold.end.column, currentScreenLineLength)
|
||||
suffix = recursiveBuildLinesForBufferRows(fold.end.row, endRow, fold.end.column, currentScreenLineLength)
|
||||
return _.compact _.flatten [prefix, placeholder, suffix]
|
||||
|
||||
if wrapColumn?
|
||||
line = line.splitAt(wrapColumn)[0]
|
||||
line.screenDelta = new Point(1, 0)
|
||||
[line].concat buildLinesForBufferRows(startRow, endRow, startColumn + wrapColumn)
|
||||
[line].concat recursiveBuildLinesForBufferRows(startRow, endRow, startColumn + wrapColumn)
|
||||
else
|
||||
[line].concat buildLinesForBufferRows(startRow + 1, endRow)
|
||||
[line].concat recursiveBuildLinesForBufferRows(startRow + 1, endRow)
|
||||
|
||||
buildLinesForBufferRows(@foldStartRowForBufferRow(startRow), endRow)
|
||||
recursiveBuildLinesForBufferRows(@foldStartRowForBufferRow(startRow), endRow)
|
||||
|
||||
foldStartRowForBufferRow: (bufferRow) ->
|
||||
@bufferRowForScreenRow(@screenRowForBufferRow(bufferRow))
|
||||
|
||||
Reference in New Issue
Block a user