mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-21 07:58:04 +03:00
handle changes that cause line to wrap once
This commit is contained in:
parent
1f6ab6f2b6
commit
3742700810
@ -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", ->
|
||||
|
||||
|
@ -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) ->
|
||||
|
Loading…
Reference in New Issue
Block a user