mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 18:24:09 +03:00
Renderer.createFoldAtBufferRow uses the fold suggester to determine which syntactic region to fold
This commit is contained in:
parent
84318277ba
commit
63a87fd83e
@ -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')
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user