From 422df7989a890db14e79bf0719f20a9a8f59ec79 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 23 Feb 2012 17:28:55 -0700 Subject: [PATCH] Handle changes inside of folds. Don't emit an event since nothing changes (since it's all folded). But update the position of the fold's end marker so when it's unfolded, things render correctly. --- spec/atom/line-folder-spec.coffee | 15 ++++++++++++++- src/atom/line-folder.coffee | 12 ++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/spec/atom/line-folder-spec.coffee b/spec/atom/line-folder-spec.coffee index 9e54d29e1..67cb78097 100644 --- a/spec/atom/line-folder-spec.coffee +++ b/spec/atom/line-folder-spec.coffee @@ -223,7 +223,20 @@ describe "LineFolder", -> expect(folder.lineForScreenRow(4).text).toBe ' while(items.length > 0) {...abc}' describe "when the old range is inside a fold", -> - it "does not trigger a change event, but ensures the change is present when the fold is destroyed", -> + it "does not trigger a change event, but updates the fold and ensures the change is present when the fold is destroyed", -> + buffer.change(new Range([4, 29], [6, 0]), 'abc') + + expect(folder.lineForScreenRow(4).text).toBe ' while(items.length > 0) {...}...concat(sort(right));' + expect(changeHandler).not.toHaveBeenCalled() + + fold1.destroy() + expect(folder.lineForScreenRow(4).text).toBe ' while(items.length > 0) {abc current < pivot ? left.push(current) : right.push(current);' + expect(folder.lineForScreenRow(5).text).toBe ' }...concat(sort(right));' + + expect(changeHandler).toHaveBeenCalled() + [[event]] = changeHandler.argsForCall + expect(event.oldRange).toEqual [[4, 0], [4, 56]] + expect(event.newRange).toEqual [[4, 0], [5, 28]] describe "when the old range surrounds a fold", -> it "removes the fold and replaces the placeholder with the new text", -> diff --git a/src/atom/line-folder.coffee b/src/atom/line-folder.coffee index b1f3232f2..3fe730c7e 100644 --- a/src/atom/line-folder.coffee +++ b/src/atom/line-folder.coffee @@ -22,7 +22,8 @@ class LineFolder logLines: (start=0, end=@lastRow())-> for row in [start..end] - console.log row, @lineForScreenRow(row).text + line = @lineForScreenRow(row).text + console.log row, line, line.length createFold: (bufferRange) -> fold = new Fold(this, bufferRange) @@ -70,12 +71,15 @@ class LineFolder @handleHighlighterChange(@lastHighlighterChangeEvent) handleHighlighterChange: (e) -> - oldScreenRange = @expandScreenRangeToLineEnds(@screenRangeForBufferRange(e.oldRange)) + oldScreenRange = @screenRangeForBufferRange(e.oldRange) + expandedOldScreenRange = @expandScreenRangeToLineEnds(oldScreenRange) lines = @buildLinesForBufferRows(e.newRange.start.row, e.newRange.end.row) @lineMap.replaceScreenRows(oldScreenRange.start.row, oldScreenRange.end.row, lines) - newScreenRange = @expandScreenRangeToLineEnds(@screenRangeForBufferRange(e.newRange)) + newScreenRange = @screenRangeForBufferRange(e.newRange) + expandedNewScreenRange = @expandScreenRangeToLineEnds(newScreenRange) - @trigger 'change', oldRange: oldScreenRange, newRange: newScreenRange + unless oldScreenRange.isEmpty() and newScreenRange.isEmpty() + @trigger 'change', oldRange: expandedOldScreenRange, newRange: expandedNewScreenRange buildLinesForBufferRows: (start, end) -> lines = [@buildLine(@screenRowForBufferRow(start))]