Renderer.createFoldAtBufferRow uses the fold suggester to determine which syntactic region to fold

This commit is contained in:
Corey Johnson & Nathan Sobo 2012-05-30 16:02:06 -06:00
parent 84318277ba
commit 63a87fd83e
2 changed files with 25 additions and 13 deletions

View File

@ -141,21 +141,29 @@ describe "Renderer", ->
expect(event.newRange).toEqual([[0, 0], [18, 2]])
expect(event.lineNumbersChanged).toBeTruthy()
describe "fold markers", ->
it "sets 'foldable' to true for screen lines that start a foldable region", ->
expect(renderer.lineForRow(0).foldable).toBeTruthy()
expect(renderer.lineForRow(1).foldable).toBeTruthy()
expect(renderer.lineForRow(2).foldable).toBeFalsy()
expect(renderer.lineForRow(3).foldable).toBeFalsy()
describe "when a foldable line is wrapped", ->
it "only marks the first screen line as foldable", ->
renderer.setMaxLineLength(20)
describe "fold suggestion", ->
describe "the foldable flag on screen lines", ->
it "sets 'foldable' to true for screen lines that start a foldable region", ->
expect(renderer.lineForRow(0).foldable).toBeTruthy()
expect(renderer.lineForRow(1).foldable).toBeFalsy()
expect(renderer.lineForRow(2).foldable).toBeTruthy()
expect(renderer.lineForRow(1).foldable).toBeTruthy()
expect(renderer.lineForRow(2).foldable).toBeFalsy()
expect(renderer.lineForRow(3).foldable).toBeFalsy()
describe "when a foldable line is wrapped", ->
it "only marks the first screen line as foldable", ->
renderer.setMaxLineLength(20)
expect(renderer.lineForRow(0).foldable).toBeTruthy()
expect(renderer.lineForRow(1).foldable).toBeFalsy()
expect(renderer.lineForRow(2).foldable).toBeTruthy()
expect(renderer.lineForRow(3).foldable).toBeFalsy()
describe ".createFoldAtBufferRow(bufferRow)", ->
it "creates a fold based on the syntactic region starting at the given row", ->
renderer.createFoldAtBufferRow(1)
fold = renderer.lineForRow(2).fold
expect(fold.startRow).toBe 2
expect(fold.endRow).toBe 9
describe "folding", ->
beforeEach ->
buffer = new Buffer(require.resolve 'fixtures/two-hundred.txt')

View File

@ -23,7 +23,7 @@ class Renderer
constructor: (@buffer, options={}) ->
@id = @constructor.idCounter++
@highlighter = new Highlighter(@buffer, options.tabText ? ' ')
@foldSuggester = new FoldSuggester(@buffer)
@foldSuggester = new FoldSuggester(@highlighter)
@maxLineLength = options.maxLineLength ? Infinity
@activeFolds = {}
@foldsById = {}
@ -53,6 +53,10 @@ class Renderer
bufferRowsForScreenRows: (startRow, endRow) ->
@lineMap.bufferRowsForScreenRows(startRow, endRow)
createFoldAtBufferRow: (bufferRow) ->
[startRow, endRow] = @foldSuggester.rowRangeForFoldAtBufferRow(bufferRow)
@createFold(startRow, endRow)
createFold: (startRow, endRow) ->
fold = new Fold(this, startRow, endRow)
@registerFold(fold)