WIP: Testing changes that cause lines to wrap

This commit is contained in:
Nathan Sobo
2012-02-08 14:25:47 -07:00
parent 5ab91c3f47
commit 4b350598a5
2 changed files with 30 additions and 3 deletions

View File

@@ -48,8 +48,9 @@ describe "LineWrapper", ->
expect(screenLines[2].endColumn).toBe 65
expect(_.pluck(screenLines[2], 'value').join('')).toBe 'right.push(current);'
fdescribe "when the buffer changes", ->
describe "when the buffer changes", ->
changeHandler = null
longText = '0123456789ABCDEF'
beforeEach ->
changeHandler = jasmine.createSpy('changeHandler')
@@ -65,8 +66,25 @@ describe "LineWrapper", ->
[event] = changeHandler.argsForCall[0]
expect(event.oldRange).toEqual(new Range([0, 10], [0, 10]))
expect(event.newRange).toEqual(new Range([0, 10], [0, 11]))
changeHandler.reset()
# below a wrapped line
buffer.insert([4, 10], 'foo')
expect(tokensText(wrapper.tokensForScreenRow(5))).toContain 'fooitems'
expect(changeHandler).toHaveBeenCalled()
[event] = changeHandler.argsForCall[0]
expect(event.oldRange).toEqual(new Range([5, 10], [5, 10]))
expect(event.newRange).toEqual(new Range([5, 10], [5, 13]))
describe "when the update causes the line to wrap once", ->
fit "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
describe "when the update causes the line to wrap multiple times", ->

View File

@@ -1,6 +1,7 @@
_ = require 'underscore'
Point = require 'point'
EventEmitter = require 'event-emitter'
Point = require 'point'
Range = require 'range'
getWordRegex = -> /\b[^\s]+/g
@@ -11,7 +12,9 @@ class LineWrapper
@buildWrappedLines()
@highlighter.on 'change', (e) =>
@wrappedLines[e.oldRange.start.row] = @buildWrappedLineForBufferRow(e.newRange.start.row)
@trigger 'change', e
oldRange = @screenRangeFromBufferRange(e.oldRange)
newRange = @screenRangeFromBufferRange(e.newRange)
@trigger 'change', { oldRange, newRange }
setMaxLength: (@maxLength) ->
@buildWrappedLines()
@@ -58,6 +61,12 @@ class LineWrapper
{ screenLines }
screenRangeFromBufferRange: (bufferRange) ->
start = @screenPositionFromBufferPosition(bufferRange.start)
end = @screenPositionFromBufferPosition(bufferRange.end)
new Range(start,end)
screenPositionFromBufferPosition: (bufferPosition) ->
bufferPosition = Point.fromObject(bufferPosition)
row = 0