Base folds on buffer markers, since they don't rely on screen coords

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.
This commit is contained in:
Nathan Sobo
2013-05-01 16:14:25 -06:00
parent 49b17023a5
commit 6153375c76
2 changed files with 6 additions and 7 deletions

View File

@@ -104,8 +104,8 @@ class DisplayBuffer
# Returns the new {Fold}.
createFold: (startRow, endRow) ->
foldMarker =
@findMarker({class: 'fold', startRow, endRow}) ?
@markBufferRange([[startRow, 0], [endRow, Infinity]], class: 'fold')
@buffer.findMarker({class: 'fold', startRow, endRow}) ?
@buffer.markRange([[startRow, 0], [endRow, Infinity]], class: 'fold')
@foldForMarker(foldMarker)
# Public: Removes any folds found that contain the given buffer row.
@@ -129,7 +129,7 @@ class DisplayBuffer
#
# Returns an {Array} of {Fold}s.
foldsStartingAtBufferRow: (bufferRow) ->
for marker in @findMarkers(class: 'fold', startBufferRow: bufferRow)
for marker in @buffer.findMarkers(class: 'fold', startRow: bufferRow)
@foldForMarker(marker)
# Public: Given a screen row, this returns the largest fold that starts there.
@@ -161,7 +161,7 @@ class DisplayBuffer
#
# Returns an {Array} of {Fold}s.
foldsContainingBufferRow: (bufferRow) ->
for marker in @findMarkers(class: 'fold', containsBufferRow: bufferRow)
for marker in @buffer.findMarkers(class: 'fold', containsRow: bufferRow)
@foldForMarker(marker)
# Public: Given a buffer range, this converts it into a screen range.
@@ -375,9 +375,8 @@ class DisplayBuffer
@triggerChanged(event, false)
handleMarkerCreated: (marker) =>
marker = @getMarker(marker.id)
new Fold(this, marker) if marker.matchesAttributes(class: 'fold')
@trigger 'marker-created', marker
@trigger 'marker-created', @getMarker(marker.id)
buildFoldForMarker: (marker) ->

View File

@@ -26,7 +26,7 @@ class Fold
# Returns the fold's {Range} in buffer coordinates
getBufferRange: ->
@marker.getBufferRange()
@marker.getRange()
# Returns the fold's start row as a {Number}.
getStartRow: ->