WIP: Handle changes that aren't affected by wrapping

This commit is contained in:
Nathan Sobo
2012-02-08 14:04:55 -07:00
parent ce90cbc0ce
commit 5ab91c3f47
3 changed files with 46 additions and 1 deletions

View File

@@ -1,9 +1,10 @@
Buffer = require 'buffer'
LineWrapper = require 'line-wrapper'
Highlighter = require 'highlighter'
Range = require 'range'
_ = require 'underscore'
fdescribe "LineWrapper", ->
describe "LineWrapper", ->
[wrapper, buffer] = []
beforeEach ->
@@ -47,6 +48,47 @@ fdescribe "LineWrapper", ->
expect(screenLines[2].endColumn).toBe 65
expect(_.pluck(screenLines[2], 'value').join('')).toBe 'right.push(current);'
fdescribe "when the buffer changes", ->
changeHandler = null
beforeEach ->
changeHandler = jasmine.createSpy('changeHandler')
wrapper.on 'change', changeHandler
describe "when an unwrapped line is updated", ->
describe "when the update does not cause the line to wrap", ->
it "updates tokens for the corresponding screen line and emits a change event", ->
buffer.insert([0, 10], 'h')
expect(tokensText(wrapper.tokensForScreenRow(0))).toContain 'quickshort'
expect(changeHandler).toHaveBeenCalled()
[event] = changeHandler.argsForCall[0]
expect(event.oldRange).toEqual(new Range([0, 10], [0, 10]))
expect(event.newRange).toEqual(new Range([0, 10], [0, 11]))
describe "when the update causes the line to wrap once", ->
describe "when the update causes the line to wrap multiple times", ->
describe "when a wrapped line is updated", ->
describe "when the update does not cause the line to un-wrap", ->
describe "when the update causes the line to no longer be wrapped", ->
describe "when the update causes a line that was wrapped twice to be only wrapped once", ->
describe "when the update causes the line to wrap a second time", ->
describe "when a line is inserted", ->
describe "when the line is wrapped", ->
describe "when the line is not wrapped", ->
describe "when a line is removed", ->
describe "when the line is wrapped", ->
describe "when the line is not wrapped", ->
describe ".tokensForScreenRow(row)", ->
it "returns tokens for the line fragment corresponding to the given screen row", ->
expect(wrapper.tokensForScreenRow(3)).toEqual(wrapper.wrappedLines[3].screenLines[0])

View File

@@ -78,6 +78,8 @@ window.pixelPositionForPoint = (editor, point) ->
pageX = editor.lines.offset().left + point.column * editor.charWidth + 1 # ensure the pixel is inside the char
[pageX, pageY]
window.tokensText = (tokens) ->
_.pluck(tokens, 'value').join('')
$.fn.resultOfTrigger = (type) ->
event = $.Event(type)

View File

@@ -11,6 +11,7 @@ class LineWrapper
@buildWrappedLines()
@highlighter.on 'change', (e) =>
@wrappedLines[e.oldRange.start.row] = @buildWrappedLineForBufferRow(e.newRange.start.row)
@trigger 'change', e
setMaxLength: (@maxLength) ->
@buildWrappedLines()