handle changes that cause line to wrap once

This commit is contained in:
Corey Johnson 2012-02-08 14:05:28 -08:00
parent 1f6ab6f2b6
commit 3742700810
2 changed files with 13 additions and 2 deletions

View File

@ -78,13 +78,16 @@ fdescribe "LineWrapper", ->
describe "when the update causes the line to wrap once", ->
fit "updates tokens for the corresponding screen lines and emits a change event", ->
it "updates tokens for the corresponding screen lines and emits a change event", ->
buffer.insert([2, 4], longText)
expect(tokensText(wrapper.tokensForScreenRow(2))).toBe ' 0123456789ABCDEFif (items.length <= 1) return '
expect(tokensText(wrapper.tokensForScreenRow(3))).toBe 'items;'
expect(tokensText(wrapper.tokensForScreenRow(4))).toBe ' var pivot = items.shift(), current, left = [], '
# LEFT OFF HERE: Test change event
expect(changeHandler).toHaveBeenCalled()
[event] = changeHandler.argsForCall[0]
expect(event.oldRange).toEqual(new Range([2, 4], [2, 4]))
expect(event.newRange).toEqual(new Range([2, 4], [3, 6]))
describe "when the update causes the line to wrap multiple times", ->

View File

@ -11,9 +11,17 @@ class LineWrapper
@buffer = @highlighter.buffer
@buildWrappedLines()
@highlighter.on 'change', (e) =>
oldCount = @wrappedLines[e.oldRange.start.row].screenLines.length
@wrappedLines[e.oldRange.start.row] = @buildWrappedLineForBufferRow(e.newRange.start.row)
newCount = @wrappedLines[e.oldRange.start.row].screenLines.length
oldRange = @screenRangeFromBufferRange(e.oldRange)
newRange = @screenRangeFromBufferRange(e.newRange)
if newCount > oldCount
newRange.end.row += newCount - oldCount
newRange.end.column = @tokensForScreenRow(newRange.end.row).textLength
@trigger 'change', { oldRange, newRange }
setMaxLength: (@maxLength) ->