From 6153375c768967f6d52f8da1720352850bac9927 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 1 May 2013 16:14:25 -0600 Subject: [PATCH] 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. --- src/app/display-buffer.coffee | 11 +++++------ src/app/fold.coffee | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/app/display-buffer.coffee b/src/app/display-buffer.coffee index 04a8e7ee4..60d1d36c7 100644 --- a/src/app/display-buffer.coffee +++ b/src/app/display-buffer.coffee @@ -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) -> diff --git a/src/app/fold.coffee b/src/app/fold.coffee index cc47e7494..f280a1303 100644 --- a/src/app/fold.coffee +++ b/src/app/fold.coffee @@ -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: ->