mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-14 04:29:04 +03:00
Add fold-all event to editor
This commit is contained in:
parent
1dce0ad2e7
commit
2623724fd4
@ -2457,6 +2457,14 @@ describe "Editor", ->
|
||||
editor.trigger "toggle-fold"
|
||||
expect(editor.screenLineForRow(1).fold).toBeUndefined()
|
||||
|
||||
describe "when a fold-all event is triggered", ->
|
||||
it "creates folds on every line that can be folded", ->
|
||||
editor.setCursorBufferPosition([5,13])
|
||||
|
||||
editor.trigger "fold-all"
|
||||
expect(editor.screenLineForRow(0).fold).toBeDefined()
|
||||
expect(editor.screenLineForRow(1)).toBeUndefined()
|
||||
|
||||
describe "primitive folding", ->
|
||||
beforeEach ->
|
||||
editor.setBuffer(new Buffer(require.resolve('fixtures/two-hundred.txt')))
|
||||
|
@ -157,6 +157,25 @@ describe "Renderer", ->
|
||||
expect(renderer.lineForRow(2).foldable).toBeTruthy()
|
||||
expect(renderer.lineForRow(3).foldable).toBeFalsy()
|
||||
|
||||
describe ".foldAll()", ->
|
||||
it "folds every foldable line", ->
|
||||
renderer.foldAll()
|
||||
fold = renderer.lineForRow(0).fold
|
||||
expect(fold).toBeDefined()
|
||||
expect([fold.startRow, fold.endRow]).toEqual [0,12]
|
||||
|
||||
expect(Object.keys(renderer.activeFolds).length).toBe(3)
|
||||
expect(renderer.activeFolds[1].length).toBe(1)
|
||||
expect(renderer.activeFolds[4].length).toBe(1)
|
||||
|
||||
it "doesn't fold lines that are already folded", ->
|
||||
renderer.toggleFoldAtBufferRow(4)
|
||||
renderer.foldAll()
|
||||
expect(Object.keys(renderer.activeFolds).length).toBe(3)
|
||||
expect(renderer.activeFolds[0].length).toBe(1)
|
||||
expect(renderer.activeFolds[1].length).toBe(1)
|
||||
expect(renderer.activeFolds[4].length).toBe(1)
|
||||
|
||||
describe ".toggleFoldAtBufferRow(bufferRow)", ->
|
||||
describe "when bufferRow can be folded", ->
|
||||
it "creates/destroys a fold based on the syntactic region starting at the given row", ->
|
||||
|
@ -120,6 +120,7 @@ class Editor extends View
|
||||
'undo': @undo
|
||||
'redo': @redo
|
||||
'toggle-soft-wrap': @toggleSoftWrap
|
||||
'fold-all': @foldAll
|
||||
'toggle-fold': @toggleFold
|
||||
'fold-selection': @foldSelection
|
||||
'unfold': => @unfoldRow(@getCursorBufferPosition().row)
|
||||
@ -805,6 +806,9 @@ class Editor extends View
|
||||
for cursor in @getCursors()
|
||||
do (cursor) -> cursor.resetCursorAnimation()
|
||||
|
||||
foldAll: ->
|
||||
@renderer.foldAll()
|
||||
|
||||
toggleFold: ->
|
||||
@renderer.toggleFoldAtBufferRow(@getCursorBufferPosition().row)
|
||||
|
||||
|
@ -53,6 +53,13 @@ class Renderer
|
||||
bufferRowsForScreenRows: (startRow, endRow) ->
|
||||
@lineMap.bufferRowsForScreenRows(startRow, endRow)
|
||||
|
||||
foldAll: ->
|
||||
for currentRow in [@buffer.getLastRow()..0]
|
||||
[startRow, endRow] = @foldSuggester.rowRangeForFoldAtBufferRow(currentRow) ? []
|
||||
continue unless startRow?
|
||||
|
||||
@createFold(startRow, endRow)
|
||||
|
||||
toggleFoldAtBufferRow: (bufferRow) ->
|
||||
for currentRow in [bufferRow..0]
|
||||
[startRow, endRow] = @foldSuggester.rowRangeForFoldAtBufferRow(currentRow) ? []
|
||||
@ -65,7 +72,12 @@ class Renderer
|
||||
|
||||
break
|
||||
|
||||
foldFor: (startRow, endRow) ->
|
||||
_.find @activeFolds[startRow] ? [], (fold) ->
|
||||
fold.startRow == startRow and fold.endRow == endRow
|
||||
|
||||
createFold: (startRow, endRow) ->
|
||||
return fold if fold = @foldFor(startRow, endRow)
|
||||
fold = new Fold(this, startRow, endRow)
|
||||
@registerFold(fold)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user