From 83dc1c76ef13dbd172cd6366fb8b90c1e1e22628 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 27 Feb 2014 19:31:23 -0800 Subject: [PATCH 1/2] Add a spec that corrupts the row map by partially editing a fold --- spec/display-buffer-spec.coffee | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/display-buffer-spec.coffee b/spec/display-buffer-spec.coffee index f10e9844d..ab937ca97 100644 --- a/spec/display-buffer-spec.coffee +++ b/spec/display-buffer-spec.coffee @@ -460,6 +460,12 @@ describe "DisplayBuffer", -> expect(changeHandler).toHaveBeenCalledWith(start: 3, end: 3, screenDelta: 1, bufferDelta: 1) + describe "when the change starts at the beginning of a fold but does not extend to the end (regression)", -> + it "preserves a proper mapping between buffer and screen coordinates", -> + expect(displayBuffer.screenPositionForBufferPosition([8, 0])).toEqual [4, 0] + buffer.setTextInRange([[2, 0], [3, 0]], "\n") + expect(displayBuffer.screenPositionForBufferPosition([8, 0])).toEqual [4, 0] + describe "position translation", -> it "translates positions to account for folded lines and characters and the placeholder", -> fold = displayBuffer.createFold(4, 7) From dc5dc608ba85ce5550ab33539fb60d3753ff4983 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 28 Feb 2014 10:04:33 -0800 Subject: [PATCH 2/2] Avoid row map corruption when replacing a subset of a fold's buffer rows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #1576 When splicing regions into the row map, we always express the starting buffer row, then the number of buffer rows covered by the regions we're inserting. When we're inserting regions representing folds, they always extend to the end of a fold, so we need to ensure the endBufferRow also extends to the end of the fold. For example, say rows [5…10] are folded, and we handle a replacement of rows [5…8]. We will still insert a region for the fold covering 1 screen row and 5 buffer rows, so we need to update the endBufferRow to extend to the end of the fold as well (10). --- src/display-buffer.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/src/display-buffer.coffee b/src/display-buffer.coffee index 49227c5a0..74ce5afb2 100644 --- a/src/display-buffer.coffee +++ b/src/display-buffer.coffee @@ -584,6 +584,7 @@ class DisplayBuffer extends Model updateScreenLines: (startBufferRow, endBufferRow, bufferDelta=0, options={}) -> startBufferRow = @rowMap.bufferRowRangeForBufferRow(startBufferRow)[0] + endBufferRow = @rowMap.bufferRowRangeForBufferRow(endBufferRow - 1)[1] startScreenRow = @rowMap.screenRowRangeForBufferRow(startBufferRow)[0] endScreenRow = @rowMap.screenRowRangeForBufferRow(endBufferRow - 1)[1]