Add TokenizedBuffer.prototype.foldableRowsForRowRange

This commit is contained in:
Antonio Scandurra
2016-02-17 10:28:38 +01:00
parent 0afa9bb21c
commit 012fa354c4
4 changed files with 14 additions and 21 deletions

View File

@@ -413,6 +413,9 @@ class DisplayBuffer extends Model
isFoldedAtScreenRow: (screenRow) ->
@largestFoldContainingBufferRow(@bufferRowForScreenRow(screenRow))?
foldableBufferRowsForBufferRowRange: (startRow, endRow) ->
@tokenizedBuffer.foldableRowsForRowRange(startRow, endRow)
# Destroys the fold with the given id
destroyFoldWithId: (id) ->
@foldsByMarkerId[id]?.destroy()

View File

@@ -599,6 +599,7 @@ class TextEditorPresenter
if endRow > startRow
bufferRows = @model.bufferRowsForScreenRows(startRow, endRow - 1)
foldableBufferRows = @model.foldableBufferRowsForBufferRowRange(bufferRows[0], bufferRows[bufferRows.length - 1])
for bufferRow, i in bufferRows
if bufferRow is lastBufferRow
softWrapped = true
@@ -609,7 +610,7 @@ class TextEditorPresenter
screenRow = startRow + i
line = @model.tokenizedLineForScreenRow(screenRow)
decorationClasses = @lineNumberDecorationClassesForRow(screenRow)
foldable = @model.isFoldableAtScreenRow(screenRow)
foldable = foldableBufferRows.has(bufferRow)
blockDecorationsBeforeCurrentScreenRowHeight = @lineTopIndex.pixelPositionAfterBlocksForRow(screenRow) - @lineTopIndex.pixelPositionBeforeBlocksForRow(screenRow)
blockDecorationsHeight = blockDecorationsBeforeCurrentScreenRowHeight
if screenRow % @tileSize isnt 0

View File

@@ -2940,7 +2940,7 @@ class TextEditor extends Model
# Returns a {Boolean}.
isFoldableAtBufferRow: (bufferRow) ->
# @languageMode.isFoldableAtBufferRow(bufferRow)
@displayBuffer.tokenizedBuffer.tokenizedLineForRow(bufferRow)?.foldable ? false
@foldableBufferRowsForBufferRowRange(bufferRow, bufferRow).has(bufferRow)
# Extended: Determine whether the given row in screen coordinates is foldable.
#
@@ -2953,6 +2953,9 @@ class TextEditor extends Model
bufferRow = @displayBuffer.bufferRowForScreenRow(screenRow)
@isFoldableAtBufferRow(bufferRow)
foldableBufferRowsForBufferRowRange: (startRow, endRow) ->
@displayBuffer.foldableBufferRowsForBufferRowRange(startRow, endRow)
# Extended: Fold the given buffer row if it isn't currently folded, and unfold
# it otherwise.
toggleFoldAtBufferRow: (bufferRow) ->

View File

@@ -210,8 +210,6 @@ class TokenizedBuffer extends Model
@validateRow(endRow)
@invalidateRow(endRow + 1) unless filledRegion
[startRow, endRow] = @updateFoldableStatus(startRow, endRow)
event = {start: startRow, end: endRow, delta: 0}
@emitter.emit 'did-change', event
@@ -271,9 +269,6 @@ class TokenizedBuffer extends Model
if newEndStack and not _.isEqual(newEndStack, previousEndStack)
@invalidateRow(end + delta + 1)
[start, end] = @updateFoldableStatus(start, end + delta)
end -= delta
event = {start, end, delta, bufferChange: e}
@emitter.emit 'did-change', event
@@ -287,23 +282,14 @@ class TokenizedBuffer extends Model
row - increment
updateFoldableStatus: (startRow, endRow) ->
return [startRow, endRow]
return [startRow, endRow] if @largeFileMode
foldableRowsForRowRange: (startRow, endRow) ->
scanStartRow = @buffer.previousNonBlankRow(startRow) ? startRow
scanStartRow-- while scanStartRow > 0 and @tokenizedLineForRow(scanStartRow).isComment()
scanEndRow = @buffer.nextNonBlankRow(endRow) ? endRow
for row in [scanStartRow..scanEndRow] by 1
foldable = @isFoldableAtRow(row)
line = @tokenizedLineForRow(row)
unless line.foldable is foldable
line.foldable = foldable
startRow = Math.min(startRow, row)
endRow = Math.max(endRow, row)
[startRow, endRow]
foldableRows = new Set
for row in [scanStartRow..scanEndRow] by 1 when @isFoldableAtRow(row)
foldableRows.add(row)
foldableRows
isFoldableAtRow: (row) ->
if @largeFileMode