mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
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.
This commit is contained in:
@@ -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", ->
|
||||
|
||||
@@ -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))]
|
||||
|
||||
Reference in New Issue
Block a user