mirror of
https://github.com/atom/atom.git
synced 2026-02-05 12:15:07 -05:00
When creating a display buffer for buffers that already have fold markers, which we'll eventually do on refresh, basing folds on full-blown display buffer markers is a problem because we end up creating display buffer markers during construction of the line map. When we create a display buffer marker it memoizes its screen positions, but since the line map isn't built yet we have nothing to translate against. Basically, since the line map depends on folds, folds can't depend on the line map. Luckily, they don't need to. Buffer markers work just fine.
58 lines
1.5 KiB
CoffeeScript
58 lines
1.5 KiB
CoffeeScript
Range = require 'range'
|
|
Point = require 'point'
|
|
|
|
# Public: Represents a fold that collapses multiple buffer lines into a single
|
|
# line on the screen.
|
|
#
|
|
# Their creation is managed by the {DisplayBuffer}.
|
|
module.exports =
|
|
class Fold
|
|
displayBuffer: null
|
|
marker: null
|
|
|
|
# Internal
|
|
constructor: (@displayBuffer, @marker) ->
|
|
@displayBuffer.foldsByMarkerId[@marker.id] = this
|
|
@updateDisplayBuffer()
|
|
@marker.on 'destroyed', => @destroyed()
|
|
|
|
# Returns whether this fold is contained within another fold
|
|
isInsideLargerFold: ->
|
|
@displayBuffer.findMarker(class: 'fold', containsBufferRange: @getBufferRange())?
|
|
|
|
# Destroys this fold
|
|
destroy: ->
|
|
@marker.destroy()
|
|
|
|
# Returns the fold's {Range} in buffer coordinates
|
|
getBufferRange: ->
|
|
@marker.getRange()
|
|
|
|
# Returns the fold's start row as a {Number}.
|
|
getStartRow: ->
|
|
@getBufferRange().start.row
|
|
|
|
# Returns the fold's end row as a {Number}.
|
|
getEndRow: ->
|
|
@getBufferRange().end.row
|
|
|
|
# Returns a {String} representation of the fold.
|
|
inspect: ->
|
|
"Fold(#{@getStartRow()}, #{@getEndRow()})"
|
|
|
|
# Retrieves the number of buffer rows spanned by the fold.
|
|
#
|
|
# Returns a {Number}.
|
|
getBufferRowCount: ->
|
|
@getEndRow() - @getStartRow() + 1
|
|
|
|
## Internal ##
|
|
|
|
updateDisplayBuffer: ->
|
|
unless @isInsideLargerFold()
|
|
@displayBuffer.updateScreenLines(@getStartRow(), @getEndRow(), 0, updateMarkers: true)
|
|
|
|
destroyed: ->
|
|
delete @displayBuffer.foldsByMarkerId[@marker.id]
|
|
@updateDisplayBuffer()
|