mirror of
https://github.com/atom/atom.git
synced 2026-02-12 15:45:23 -05:00
Merge branch 'making-folding-better'
This commit is contained in:
@@ -59,26 +59,23 @@ class DisplayBuffer
|
||||
|
||||
@createFold(startRow, endRow)
|
||||
|
||||
toggleFoldAtBufferRow: (bufferRow) ->
|
||||
unfoldAll: ->
|
||||
for row in [@buffer.getLastRow()..0]
|
||||
@activeFolds[row]?.forEach (fold) => @destroyFold(fold)
|
||||
|
||||
foldBufferRow: (bufferRow) ->
|
||||
for currentRow in [bufferRow..0]
|
||||
[startRow, endRow] = @languageMode.rowRangeForFoldAtBufferRow(currentRow) ? []
|
||||
continue unless startRow? and startRow <= bufferRow <= endRow
|
||||
fold = @largestFoldStartingAtBufferRow(startRow)
|
||||
continue if fold
|
||||
|
||||
if fold = @largestFoldStartingAtBufferRow(startRow)
|
||||
fold.destroy()
|
||||
else
|
||||
@createFold(startRow, endRow)
|
||||
@createFold(startRow, endRow)
|
||||
|
||||
break
|
||||
return
|
||||
|
||||
isFoldContainedByActiveFold: (fold) ->
|
||||
for row, folds of @activeFolds
|
||||
for otherFold in folds
|
||||
return otherFold if fold != otherFold and fold.isContainedByFold(otherFold)
|
||||
|
||||
foldFor: (startRow, endRow) ->
|
||||
_.find @activeFolds[startRow] ? [], (fold) ->
|
||||
fold.startRow == startRow and fold.endRow == endRow
|
||||
unfoldBufferRow: (bufferRow) ->
|
||||
@largestFoldContainingBufferRow(bufferRow)?.destroy()
|
||||
|
||||
createFold: (startRow, endRow) ->
|
||||
return fold if fold = @foldFor(startRow, endRow)
|
||||
@@ -97,6 +94,15 @@ class DisplayBuffer
|
||||
|
||||
fold
|
||||
|
||||
isFoldContainedByActiveFold: (fold) ->
|
||||
for row, folds of @activeFolds
|
||||
for otherFold in folds
|
||||
return otherFold if fold != otherFold and fold.isContainedByFold(otherFold)
|
||||
|
||||
foldFor: (startRow, endRow) ->
|
||||
_.find @activeFolds[startRow] ? [], (fold) ->
|
||||
fold.startRow == startRow and fold.endRow == endRow
|
||||
|
||||
destroyFold: (fold) ->
|
||||
@unregisterFold(fold.startRow, fold)
|
||||
|
||||
@@ -124,6 +130,7 @@ class DisplayBuffer
|
||||
folds = @activeFolds[bufferRow]
|
||||
_.remove(folds, fold)
|
||||
delete @foldsById[fold.id]
|
||||
delete @activeFolds[bufferRow] if folds.length == 0
|
||||
|
||||
largestFoldStartingAtBufferRow: (bufferRow) ->
|
||||
return unless folds = @activeFolds[bufferRow]
|
||||
|
||||
@@ -201,18 +201,28 @@ class EditSession
|
||||
redo: ->
|
||||
@buffer.redo(this)
|
||||
|
||||
foldSelection: ->
|
||||
selection.fold() for selection in @getSelections()
|
||||
|
||||
foldAll: ->
|
||||
@displayBuffer.foldAll()
|
||||
|
||||
toggleFold: ->
|
||||
bufferRow = @bufferPositionForScreenPosition(@getCursorScreenPosition()).row
|
||||
@toggleFoldAtBufferRow(bufferRow)
|
||||
unfoldAll: ->
|
||||
@displayBuffer.unfoldAll()
|
||||
|
||||
toggleFoldAtBufferRow: (bufferRow) ->
|
||||
@displayBuffer.toggleFoldAtBufferRow(bufferRow)
|
||||
foldCurrentRow: ->
|
||||
bufferRow = @bufferPositionForScreenPosition(@getCursorScreenPosition()).row
|
||||
@foldBufferRow(bufferRow)
|
||||
|
||||
foldBufferRow: (bufferRow) ->
|
||||
@displayBuffer.foldBufferRow(bufferRow)
|
||||
|
||||
unfoldCurrentRow: ->
|
||||
bufferRow = @bufferPositionForScreenPosition(@getCursorScreenPosition()).row
|
||||
@unfoldBufferRow(bufferRow)
|
||||
|
||||
unfoldBufferRow: (bufferRow) ->
|
||||
@displayBuffer.unfoldBufferRow(bufferRow)
|
||||
|
||||
foldSelection: ->
|
||||
selection.fold() for selection in @getSelections()
|
||||
|
||||
createFold: (startRow, endRow) ->
|
||||
@displayBuffer.createFold(startRow, endRow)
|
||||
@@ -224,9 +234,6 @@ class EditSession
|
||||
for row in [bufferRange.start.row..bufferRange.end.row]
|
||||
@destroyFoldsContainingBufferRow(row)
|
||||
|
||||
unfoldCurrentRow: ->
|
||||
@largestFoldStartingAtBufferRow(@getLastCursor().getBufferRow())?.destroy()
|
||||
|
||||
destroyFold: (foldId) ->
|
||||
fold = @displayBuffer.foldsById[foldId]
|
||||
fold.destroy()
|
||||
@@ -235,9 +242,6 @@ class EditSession
|
||||
isFoldedAtScreenRow: (screenRow) ->
|
||||
@lineForScreenRow(screenRow).fold?
|
||||
|
||||
largestFoldStartingAtBufferRow: (bufferRow) ->
|
||||
@displayBuffer.largestFoldStartingAtBufferRow(bufferRow)
|
||||
|
||||
largestFoldContainingBufferRow: (bufferRow) ->
|
||||
@displayBuffer.largestFoldContainingBufferRow(bufferRow)
|
||||
|
||||
|
||||
@@ -139,9 +139,10 @@ class Editor extends View
|
||||
'newline-below': @insertNewlineBelow
|
||||
'toggle-soft-wrap': @toggleSoftWrap
|
||||
'fold-all': @foldAll
|
||||
'toggle-fold': @toggleFold
|
||||
'unfold-all': @unfoldAll
|
||||
'fold-current-row': @foldCurrentRow
|
||||
'unfold-current-row': @unfoldCurrentRow
|
||||
'fold-selection': @foldSelection
|
||||
'unfold': => @unfoldCurrentRow()
|
||||
'split-left': @splitLeft
|
||||
'split-right': @splitRight
|
||||
'split-up': @splitUp
|
||||
@@ -220,13 +221,14 @@ class Editor extends View
|
||||
undo: -> @activeEditSession.undo()
|
||||
redo: -> @activeEditSession.redo()
|
||||
createFold: (startRow, endRow) -> @activeEditSession.createFold(startRow, endRow)
|
||||
foldCurrentRow: -> @activeEditSession.foldCurrentRow()
|
||||
unfoldCurrentRow: -> @activeEditSession.unfoldCurrentRow()
|
||||
foldAll: -> @activeEditSession.foldAll()
|
||||
unfoldAll: -> @activeEditSession.unfoldAll()
|
||||
foldSelection: -> @activeEditSession.foldSelection()
|
||||
destroyFold: (foldId) -> @activeEditSession.destroyFold(foldId)
|
||||
destroyFoldsContainingBufferRow: (bufferRow) -> @activeEditSession.destroyFoldsContainingBufferRow(bufferRow)
|
||||
toggleFold: -> @activeEditSession.toggleFold()
|
||||
isFoldedAtScreenRow: (screenRow) -> @activeEditSession.isFoldedAtScreenRow(screenRow)
|
||||
unfoldCurrentRow: -> @activeEditSession.unfoldCurrentRow()
|
||||
|
||||
lineForScreenRow: (screenRow) -> @activeEditSession.lineForScreenRow(screenRow)
|
||||
linesForScreenRows: (start, end) -> @activeEditSession.linesForScreenRows(start, end)
|
||||
|
||||
@@ -17,10 +17,11 @@ window.keymap.bindKeys '.editor',
|
||||
'meta-z': 'undo'
|
||||
'meta-Z': 'redo'
|
||||
'alt-meta-w': 'toggle-soft-wrap'
|
||||
'ctrl-9': 'toggle-fold'
|
||||
'ctrl-(': 'fold-all'
|
||||
'ctrl-[': 'fold-current-row'
|
||||
'ctrl-]': 'unfold-current-row'
|
||||
'ctrl-{': 'fold-all'
|
||||
'ctrl-}': 'unfold-all'
|
||||
'alt-meta-ctrl-f': 'fold-selection'
|
||||
'alt-meta-u': 'unfold'
|
||||
'alt-meta-left': 'split-left'
|
||||
'alt-meta-right': 'split-right'
|
||||
'alt-meta-up': 'split-up'
|
||||
|
||||
Reference in New Issue
Block a user