Add fold-all event to editor

This commit is contained in:
Corey Johnson
2012-06-01 10:48:35 -07:00
parent 1dce0ad2e7
commit 2623724fd4
4 changed files with 43 additions and 0 deletions

View File

@@ -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)

View File

@@ -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)