Eliminate old ScreenLine

This commit is contained in:
Nathan Sobo
2012-02-22 10:27:49 -07:00
parent 52e1400dc4
commit ab9a93b390
9 changed files with 107 additions and 213 deletions

View File

@@ -12,9 +12,9 @@ describe "LineMap", ->
buffer = new Buffer(require.resolve 'fixtures/sample.js')
highlighter = new Highlighter(buffer)
map = new LineMap
[line0, line1, line2, line3, line4] = highlighter.lineFragmentsForRows(0, 4)
[line0, line1, line2, line3, line4] = highlighter.screenLinesForRows(0, 4)
describe ".insertAtBufferRow(row, lineFragment(s))", ->
describe ".insertAtBufferRow(row, screenLine(s))", ->
describe "when passed a single, line fragment", ->
it "inserts the line fragment before the specified buffer row", ->
map.insertAtBufferRow(0, line1)
@@ -22,10 +22,10 @@ describe "LineMap", ->
map.insertAtBufferRow(2, line3)
map.insertAtBufferRow(2, line2)
expect(map.lineFragmentsForScreenRow(0)).toEqual [line0]
expect(map.lineFragmentsForScreenRow(1)).toEqual [line1]
expect(map.lineFragmentsForScreenRow(2)).toEqual [line2]
expect(map.lineFragmentsForScreenRow(3)).toEqual [line3]
expect(map.screenLinesForScreenRow(0)).toEqual [line0]
expect(map.screenLinesForScreenRow(1)).toEqual [line1]
expect(map.screenLinesForScreenRow(2)).toEqual [line2]
expect(map.screenLinesForScreenRow(3)).toEqual [line3]
describe "when passed an array of line fragments", ->
it "inserts the given line fragments before the specified buffer row", ->
@@ -33,23 +33,23 @@ describe "LineMap", ->
map.insertAtBufferRow(0, [line0, line1])
map.insertAtBufferRow(4, [line4])
expect(map.lineFragmentsForScreenRow(0)).toEqual [line0]
expect(map.lineFragmentsForScreenRow(1)).toEqual [line1]
expect(map.lineFragmentsForScreenRow(2)).toEqual [line2]
expect(map.lineFragmentsForScreenRow(3)).toEqual [line3]
expect(map.lineFragmentsForScreenRow(4)).toEqual [line4]
expect(map.screenLinesForScreenRow(0)).toEqual [line0]
expect(map.screenLinesForScreenRow(1)).toEqual [line1]
expect(map.screenLinesForScreenRow(2)).toEqual [line2]
expect(map.screenLinesForScreenRow(3)).toEqual [line3]
expect(map.screenLinesForScreenRow(4)).toEqual [line4]
describe ".spliceAtBufferRow(bufferRow, rowCount, lineFragments)", ->
describe ".spliceAtBufferRow(bufferRow, rowCount, screenLines)", ->
describe "when called with a row count of 0", ->
it "inserts the given line fragments before the specified buffer row", ->
map.insertAtBufferRow(0, [line0, line1, line2])
map.spliceAtBufferRow(1, 0, [line3, line4])
expect(map.lineFragmentsForScreenRow(0)).toEqual [line0]
expect(map.lineFragmentsForScreenRow(1)).toEqual [line3]
expect(map.lineFragmentsForScreenRow(2)).toEqual [line4]
expect(map.lineFragmentsForScreenRow(3)).toEqual [line1]
expect(map.lineFragmentsForScreenRow(4)).toEqual [line2]
expect(map.screenLinesForScreenRow(0)).toEqual [line0]
expect(map.screenLinesForScreenRow(1)).toEqual [line3]
expect(map.screenLinesForScreenRow(2)).toEqual [line4]
expect(map.screenLinesForScreenRow(3)).toEqual [line1]
expect(map.screenLinesForScreenRow(4)).toEqual [line2]
describe "when called with a row count of 1", ->
describe "when the specified buffer row is spanned by a single line fragment", ->
@@ -58,10 +58,10 @@ describe "LineMap", ->
map.spliceAtBufferRow(1, 1, [line3, line4])
expect(map.bufferLineCount()).toBe 4
expect(map.lineFragmentsForScreenRow(0)).toEqual [line0]
expect(map.lineFragmentsForScreenRow(1)).toEqual [line3]
expect(map.lineFragmentsForScreenRow(2)).toEqual [line4]
expect(map.lineFragmentsForScreenRow(3)).toEqual [line2]
expect(map.screenLinesForScreenRow(0)).toEqual [line0]
expect(map.screenLinesForScreenRow(1)).toEqual [line3]
expect(map.screenLinesForScreenRow(2)).toEqual [line4]
expect(map.screenLinesForScreenRow(3)).toEqual [line2]
describe "when the specified buffer row is spanned by multiple line fragments", ->
it "replaces all spanning line fragments with the given line fragments", ->
@@ -72,10 +72,10 @@ describe "LineMap", ->
map.spliceAtBufferRow(1, 1, [line3a, line3b, line4])
expect(map.bufferLineCount()).toBe 4
expect(map.lineFragmentsForScreenRow(0)).toEqual [line0]
expect(map.lineFragmentsForScreenRow(1)).toEqual [line3a, line3b]
expect(map.lineFragmentsForScreenRow(2)).toEqual [line4]
expect(map.lineFragmentsForScreenRow(3)).toEqual [line2]
expect(map.screenLinesForScreenRow(0)).toEqual [line0]
expect(map.screenLinesForScreenRow(1)).toEqual [line3a, line3b]
expect(map.screenLinesForScreenRow(2)).toEqual [line4]
expect(map.screenLinesForScreenRow(3)).toEqual [line2]
describe "when called with a row count greater than 1", ->
it "replaces all line fragments spanning the multiple buffer rows with the given line fragments", ->
@@ -86,9 +86,9 @@ describe "LineMap", ->
map.spliceAtBufferRow(1, 2, [line3a, line3b, line4])
expect(map.bufferLineCount()).toBe 3
expect(map.lineFragmentsForScreenRow(0)).toEqual [line0]
expect(map.lineFragmentsForScreenRow(1)).toEqual [line3a, line3b]
expect(map.lineFragmentsForScreenRow(2)).toEqual [line4]
expect(map.screenLinesForScreenRow(0)).toEqual [line0]
expect(map.screenLinesForScreenRow(1)).toEqual [line3a, line3b]
expect(map.screenLinesForScreenRow(2)).toEqual [line4]
describe ".spliceAtScreenRow(startRow, rowCount, lineFragemnts)", ->
describe "when called with a row count of 0", ->
@@ -96,11 +96,11 @@ describe "LineMap", ->
map.insertAtBufferRow(0, [line0, line1, line2])
map.spliceAtScreenRow(1, 0, [line3, line4])
expect(map.lineFragmentsForScreenRow(0)).toEqual [line0]
expect(map.lineFragmentsForScreenRow(1)).toEqual [line3]
expect(map.lineFragmentsForScreenRow(2)).toEqual [line4]
expect(map.lineFragmentsForScreenRow(3)).toEqual [line1]
expect(map.lineFragmentsForScreenRow(4)).toEqual [line2]
expect(map.screenLinesForScreenRow(0)).toEqual [line0]
expect(map.screenLinesForScreenRow(1)).toEqual [line3]
expect(map.screenLinesForScreenRow(2)).toEqual [line4]
expect(map.screenLinesForScreenRow(3)).toEqual [line1]
expect(map.screenLinesForScreenRow(4)).toEqual [line2]
describe "when called with a row count of 1", ->
describe "when the specified screen row is spanned by a single line fragment", ->
@@ -109,10 +109,10 @@ describe "LineMap", ->
map.spliceAtScreenRow(1, 1, [line3, line4])
expect(map.bufferLineCount()).toBe 4
expect(map.lineFragmentsForScreenRow(0)).toEqual [line0]
expect(map.lineFragmentsForScreenRow(1)).toEqual [line3]
expect(map.lineFragmentsForScreenRow(2)).toEqual [line4]
expect(map.lineFragmentsForScreenRow(3)).toEqual [line2]
expect(map.screenLinesForScreenRow(0)).toEqual [line0]
expect(map.screenLinesForScreenRow(1)).toEqual [line3]
expect(map.screenLinesForScreenRow(2)).toEqual [line4]
expect(map.screenLinesForScreenRow(3)).toEqual [line2]
describe "when the specified screen row is spanned by multiple line fragments", ->
it "replaces all spanning line fragments with the given line fragments", ->
@@ -123,10 +123,10 @@ describe "LineMap", ->
map.spliceAtScreenRow(1, 1, [line3a, line3b, line4])
expect(map.bufferLineCount()).toBe 4
expect(map.lineFragmentsForScreenRow(0)).toEqual [line0]
expect(map.lineFragmentsForScreenRow(1)).toEqual [line3a, line3b]
expect(map.lineFragmentsForScreenRow(2)).toEqual [line4]
expect(map.lineFragmentsForScreenRow(3)).toEqual [line2]
expect(map.screenLinesForScreenRow(0)).toEqual [line0]
expect(map.screenLinesForScreenRow(1)).toEqual [line3a, line3b]
expect(map.screenLinesForScreenRow(2)).toEqual [line4]
expect(map.screenLinesForScreenRow(3)).toEqual [line2]
describe "when called with a row count greater than 1", ->
it "replaces all line fragments spanning the multiple buffer rows with the given line fragments", ->
@@ -137,9 +137,9 @@ describe "LineMap", ->
map.spliceAtScreenRow(1, 2, [line3a, line3b, line4])
expect(map.bufferLineCount()).toBe 3
expect(map.lineFragmentsForScreenRow(0)).toEqual [line0]
expect(map.lineFragmentsForScreenRow(1)).toEqual [line3a, line3b]
expect(map.lineFragmentsForScreenRow(2)).toEqual [line4]
expect(map.screenLinesForScreenRow(0)).toEqual [line0]
expect(map.screenLinesForScreenRow(1)).toEqual [line3a, line3b]
expect(map.screenLinesForScreenRow(2)).toEqual [line4]
describe ".linesForScreenRows(startRow, endRow)", ->
it "returns lines for the given row range, concatenating fragments that belong on a single screen line", ->

View File

@@ -3,16 +3,16 @@ Buffer = require 'buffer'
Highlighter = require 'highlighter'
describe "screenLineFragment", ->
[lineFragment, highlighter] = []
[screenLine, highlighter] = []
beforeEach ->
buffer = new Buffer(require.resolve 'fixtures/sample.js')
highlighter = new Highlighter(buffer)
lineFragment = highlighter.lineFragmentForRow(3)
screenLine = highlighter.screenLineForRow(3)
describe ".splitAt(column)", ->
it "breaks the line fragment into two fragments", ->
[left, right] = lineFragment.splitAt(31)
[left, right] = screenLine.splitAt(31)
expect(left.text).toBe ' var pivot = items.shift(), '
expect(tokensText left.tokens).toBe left.text
@@ -20,7 +20,7 @@ describe "screenLineFragment", ->
expect(tokensText right.tokens).toBe right.text
it "splits tokens if they straddle the split boundary", ->
[left, right] = lineFragment.splitAt(34)
[left, right] = screenLine.splitAt(34)
expect(left.text).toBe ' var pivot = items.shift(), cur'
expect(tokensText left.tokens).toBe left.text
@@ -30,7 +30,7 @@ describe "screenLineFragment", ->
expect(_.last(left.tokens).type).toBe right.tokens[0].type
it "ensures the returned fragments cover the span of the original line", ->
[left, right] = lineFragment.splitAt(15)
[left, right] = screenLine.splitAt(15)
expect(left.bufferDelta).toEqual [0, 15]
expect(left.screenDelta).toEqual [0, 15]
@@ -46,15 +46,15 @@ describe "screenLineFragment", ->
describe "if splitting at 0", ->
it "returns undefined for the left half", ->
expect(lineFragment.splitAt(0)).toEqual [undefined, lineFragment]
expect(screenLine.splitAt(0)).toEqual [undefined, screenLine]
describe "if splitting at a column equal to the line length", ->
it "returns an empty line fragment that spans a row for the right half", ->
[left, right] = lineFragment.splitAt(lineFragment.text.length)
[left, right] = screenLine.splitAt(screenLine.text.length)
expect(left.text).toBe lineFragment.text
expect(left.screenDelta).toEqual [0, lineFragment.text.length]
expect(left.bufferDelta).toEqual [0, lineFragment.text.length]
expect(left.text).toBe screenLine.text
expect(left.screenDelta).toEqual [0, screenLine.text.length]
expect(left.bufferDelta).toEqual [0, screenLine.text.length]
expect(right.text).toBe ''
expect(right.screenDelta).toEqual [1, 0]
@@ -62,10 +62,10 @@ describe "screenLineFragment", ->
describe ".concat(otherFragment)", ->
it "returns the concatenation of the receiver and the given fragment", ->
[left, right] = lineFragment.splitAt(14)
expect(left.concat(right)).toEqual lineFragment
[left, right] = screenLine.splitAt(14)
expect(left.concat(right)).toEqual screenLine
concatenated = lineFragment.concat(highlighter.lineFragmentForRow(4))
concatenated = screenLine.concat(highlighter.screenLineForRow(4))
expect(concatenated.text).toBe ' var pivot = items.shift(), current, left = [], right = []; while(items.length > 0) {'
expect(tokensText concatenated.tokens).toBe concatenated.text
expect(concatenated.screenDelta).toEqual [2, 0]

View File

@@ -1,50 +0,0 @@
_ = require 'underscore'
Buffer = require 'buffer'
Highlighter = require 'highlighter'
describe "ScreenLine", ->
[screenLine, highlighter] = []
beforeEach ->
buffer = new Buffer(require.resolve 'fixtures/sample.js')
highlighter = new Highlighter(buffer)
screenLine = highlighter.screenLineForRow(3)
describe ".pushToken(token)", ->
it "appends the given token to the screen line", ->
screenLine.pushToken(value: "foo", type: "bar")
expect(_.last(screenLine.tokens)).toEqual(value: "foo", type: "bar")
expect(screenLine.text).toBe ' var pivot = items.shift(), current, left = [], right = [];foo'
describe ".concat(screenLine)", ->
it "returns a new screen line combining the contents of the receiver and the given screen line", ->
otherLine = highlighter.screenLineForRow(4)
concatenated = screenLine.concat(otherLine)
expect(concatenated.text).toBe screenLine.text + otherLine.text
expect(concatenated.tokens).toEqual screenLine.tokens.concat(otherLine.tokens)
describe ".splitAt(splitColumn)", ->
describe "when the split column is less than the line length", ->
describe "when the split column is at the start of a token", ->
it "returns two screen lines", ->
[left, right] = screenLine.splitAt(31)
expect(left.text).toBe ' var pivot = items.shift(), '
expect(tokensText left.tokens).toBe left.text
expect(right.text).toBe 'current, left = [], right = [];'
expect(tokensText right.tokens).toBe right.text
describe "when the split column is in the middle of a token", ->
it "it returns two screen lines, with the token split in half", ->
[left, right] = screenLine.splitAt(34)
expect(left.text).toBe ' var pivot = items.shift(), cur'
expect(tokensText left.tokens).toBe left.text
expect(right.text).toBe 'rent, left = [], right = [];'
expect(tokensText right.tokens).toBe right.text
describe "when the split column is 0 or equals the line length", ->
it "returns a singleton array of the screen line (doesn't split it)", ->
expect(screenLine.splitAt(0)).toEqual([screenLine])
expect(screenLine.splitAt(screenLine.text.length)).toEqual([screenLine])

View File

@@ -1,6 +1,5 @@
_ = require 'underscore'
ScreenLineFragment = require 'screen-line-fragment'
ScreenLine = require 'screen-line'
EventEmitter = require 'event-emitter'
module.exports =
@@ -59,20 +58,15 @@ class Highlighter
buildScreenLineForRow: (state, row) ->
line = @buffer.getLine(row)
{tokens, state} = @tokenizer.getLineTokens(line, state)
new ScreenLine(tokens, line, state)
new ScreenLineFragment(tokens, line, [1, 0], [1, 0], { state })
screenLineForRow: (row) ->
@screenLines[row]
lineFragments: ->
@lineFragmentsForRows(0, @buffer.lastRow())
screenLinesForRows: (startRow, endRow) ->
@screenLines[startRow..endRow]
lineFragmentsForRows: (startRow, endRow) ->
for row in [startRow..endRow]
@lineFragmentForRow(row)
lineFragmentForRow: (row) ->
{ tokens, text } = @screenLines[row]
new ScreenLineFragment(tokens, text, [1, 0], [1, 0])
lastRow: ->
@screenLines.length - 1
_.extend(Highlighter.prototype, EventEmitter)

View File

@@ -11,7 +11,7 @@ class LineFolder
buildLineMap: ->
@lineMap = new LineMap
@lineMap.insertAtBufferRow(0, @highlighter.lineFragments())
@lineMap.insertAtBufferRow(0, @highlighter.screenLines)
fold: (bufferRange) ->
@activeFolds[bufferRange.start.row] ?= []
@@ -23,26 +23,15 @@ class LineFolder
@renderScreenLineForBufferRow(@bufferRowForScreenRow(screenRow))
renderScreenLineForBufferRow: (bufferRow, startColumn=0) ->
screenLine = @highlighter.lineFragmentForRow(bufferRow).splitAt(startColumn)[1]
screenLine = @highlighter.screenLineForRow(bufferRow).splitAt(startColumn)[1]
for fold in @foldsForBufferRow(bufferRow)
{ start, end } = fold.range
if start.column > startColumn
prefix = screenLine.splitAt(start.column - startColumn)[0]
suffix = @buildScreenLineForBufferRow(end.row, end.column)
suffix = @renderScreenLineForBufferRow(end.row, end.column)
return _.flatten([prefix, @buildFoldPlaceholder(fold), suffix])
screenLine
buildScreenLineForBufferRow: (bufferRow, startColumn=0) ->
screenLine = @highlighter.lineFragmentForRow(bufferRow).splitAt(startColumn)[1]
for fold in @foldsForBufferRow(bufferRow)
{ start, end } = fold.range
if start.column > startColumn
prefix = screenLine.splitAt(start.column - startColumn)[0]
suffix = @buildScreenLineForBufferRow(end.row, end.column)
screenLine = _.flatten([prefix, @buildFoldPlaceholder(fold), suffix])
return screenLine
screenLine
buildFoldPlaceholder: (fold) ->
new ScreenLineFragment([{value: '...', type: 'fold-placeholder'}], '...', [0, 3], fold.range.toDelta())

View File

@@ -6,61 +6,61 @@ Range = require 'range'
module.exports =
class LineMap
constructor: ->
@lineFragments = []
@screenLines = []
insertAtBufferRow: (bufferRow, lineFragments) ->
lineFragments = [lineFragments] unless _.isArray(lineFragments)
insertAtBufferRow: (bufferRow, screenLines) ->
screenLines = [screenLines] unless _.isArray(screenLines)
delta = new Delta
insertIndex = 0
for lineFragment in @lineFragments
nextDelta = delta.add(lineFragment.bufferDelta)
for screenLine in @screenLines
nextDelta = delta.add(screenLine.bufferDelta)
break if nextDelta.rows > bufferRow
delta = nextDelta
insertIndex++
@lineFragments[insertIndex...insertIndex] = lineFragments
@screenLines[insertIndex...insertIndex] = screenLines
spliceAtBufferRow: (startRow, rowCount, lineFragments) ->
@spliceByDelta('bufferDelta', startRow, rowCount, lineFragments)
spliceAtBufferRow: (startRow, rowCount, screenLines) ->
@spliceByDelta('bufferDelta', startRow, rowCount, screenLines)
spliceAtScreenRow: (startRow, rowCount, lineFragments) ->
@spliceByDelta('screenDelta', startRow, rowCount, lineFragments)
spliceAtScreenRow: (startRow, rowCount, screenLines) ->
@spliceByDelta('screenDelta', startRow, rowCount, screenLines)
spliceByDelta: (deltaType, startRow, rowCount, lineFragments) ->
spliceByDelta: (deltaType, startRow, rowCount, screenLines) ->
stopRow = startRow + rowCount
startIndex = undefined
stopIndex = 0
delta = new Delta
for lineFragment, i in @lineFragments
for screenLine, i in @screenLines
startIndex = i if delta.rows == startRow and not startIndex
nextDelta = delta.add(lineFragment[deltaType])
nextDelta = delta.add(screenLine[deltaType])
break if nextDelta.rows > stopRow
delta = nextDelta
stopIndex++
@lineFragments[startIndex...stopIndex] = lineFragments
@screenLines[startIndex...stopIndex] = screenLines
replaceBufferRows: (start, end, lineFragments) ->
@spliceAtBufferRow(start, end - start + 1, lineFragments)
replaceBufferRows: (start, end, screenLines) ->
@spliceAtBufferRow(start, end - start + 1, screenLines)
replaceScreenRows: (start, end, lineFragments) ->
@spliceAtScreenRow(start, end - start + 1, lineFragments)
replaceScreenRows: (start, end, screenLines) ->
@spliceAtScreenRow(start, end - start + 1, screenLines)
lineFragmentsForScreenRow: (screenRow) ->
@lineFragmentsForScreenRows(screenRow, screenRow)
screenLinesForScreenRow: (screenRow) ->
@screenLinesForScreenRows(screenRow, screenRow)
lineFragmentsForScreenRows: (startRow, endRow) ->
lineFragments = []
screenLinesForScreenRows: (startRow, endRow) ->
screenLines = []
delta = new Delta
for lineFragment in @lineFragments
for screenLine in @screenLines
break if delta.rows > endRow
lineFragments.push(lineFragment) if delta.rows >= startRow
delta = delta.add(lineFragment.screenDelta)
screenLines.push(screenLine) if delta.rows >= startRow
delta = delta.add(screenLine.screenDelta)
lineFragments
screenLines
lineForScreenRow: (row) ->
@linesForScreenRows(row, row)[0]
@@ -70,7 +70,7 @@ class LineMap
lines = []
delta = new Delta
for fragment in @lineFragments
for fragment in @screenLines
break if delta.rows > endRow
if delta.rows >= startRow
if pendingFragment
@@ -86,7 +86,7 @@ class LineMap
lineForBufferRow: (row) ->
line = null
delta = new Delta
for fragment in @lineFragments
for fragment in @screenLines
break if delta.rows > row
if delta.rows == row
if line
@@ -98,14 +98,14 @@ class LineMap
bufferLineCount: ->
delta = new Delta
for lineFragment in @lineFragments
delta = delta.add(lineFragment.bufferDelta)
for screenLine in @screenLines
delta = delta.add(screenLine.bufferDelta)
delta.rows
screenLineCount: ->
delta = new Delta
for lineFragment in @lineFragments
delta = delta.add(lineFragment.screenDelta)
for screenLine in @screenLines
delta = delta.add(screenLine.screenDelta)
delta.rows
screenPositionForBufferPosition: (bufferPosition, eagerWrap=true) ->
@@ -113,13 +113,13 @@ class LineMap
bufferDelta = new Delta
screenDelta = new Delta
for lineFragment in @lineFragments
nextDelta = bufferDelta.add(lineFragment.bufferDelta)
for screenLine in @screenLines
nextDelta = bufferDelta.add(screenLine.bufferDelta)
break if nextDelta.toPoint().greaterThan(bufferPosition)
break if nextDelta.toPoint().isEqual(bufferPosition) and not eagerWrap
bufferDelta = nextDelta
screenDelta = screenDelta.add(lineFragment.screenDelta)
screenDelta = screenDelta.add(screenLine.screenDelta)
columns = screenDelta.columns + (bufferPosition.column - bufferDelta.columns)
new Point(screenDelta.rows, columns)
@@ -129,11 +129,11 @@ class LineMap
bufferDelta = new Delta
screenDelta = new Delta
for lineFragment in @lineFragments
nextDelta = screenDelta.add(lineFragment.screenDelta)
for screenLine in @screenLines
nextDelta = screenDelta.add(screenLine.screenDelta)
break if nextDelta.toPoint().greaterThan(screenPosition)
screenDelta = nextDelta
bufferDelta = bufferDelta.add(lineFragment.bufferDelta)
bufferDelta = bufferDelta.add(screenLine.bufferDelta)
columns = bufferDelta.columns + (screenPosition.column - screenDelta.columns)
new Point(bufferDelta.rows, columns)

View File

@@ -8,7 +8,6 @@ Delta = require 'delta'
module.exports =
class LineWrapper
constructor: (@maxLength, @highlighter) ->
@buffer = @highlighter.buffer
@buildLineMap()
@highlighter.on 'change', (e) => @handleChange(e)
@@ -20,7 +19,7 @@ class LineWrapper
buildLineMap: ->
@lineMap = new LineMap
@lineMap.insertAtBufferRow 0, @buildScreenLinesForBufferRows(0, @buffer.lastRow())
@lineMap.insertAtBufferRow 0, @buildScreenLinesForBufferRows(0, @highlighter.lastRow())
handleChange: (e) ->
oldBufferRange = e.oldRange
@@ -44,7 +43,7 @@ class LineWrapper
buildScreenLinesForBufferRows: (start, end) ->
_(@highlighter
.lineFragmentsForRows(start, end)
.screenLinesForRows(start, end)
.map((screenLine) => @wrapScreenLine(screenLine))).flatten()
wrapScreenLine: (screenLine, startColumn=0) ->

View File

@@ -3,9 +3,10 @@ Delta = require 'delta'
module.exports =
class ScreenLineFragment
constructor: (@tokens, @text, screenDelta, bufferDelta) ->
constructor: (@tokens, @text, screenDelta, bufferDelta, extraFields) ->
@screenDelta = Delta.fromObject(screenDelta)
@bufferDelta = Delta.fromObject(bufferDelta)
_.extend(this, extraFields)
splitAt: (column) ->
return [undefined, this] if column == 0

View File

@@ -1,39 +0,0 @@
_ = require 'underscore'
module.exports =
class ScreenLine
tokens: null
text: null
state: null
constructor: (@tokens, @text, @state) ->
pushToken: (token) ->
@tokens.push(token)
@text += token.value
concat: (otherLine) ->
new ScreenLine(@tokens.concat(otherLine.tokens), @text + otherLine.text)
splitAt: (column) ->
return [this] if column == 0 or column >= @text.length
rightTokens = _.clone(@tokens)
leftTokens = []
leftTextLength = 0
while leftTextLength < column
if leftTextLength + rightTokens[0].value.length > column
rightTokens[0..0] = @splitTokenAt(rightTokens[0], column - leftTextLength)
nextToken = rightTokens.shift()
leftTextLength += nextToken.value.length
leftTokens.push nextToken
leftLine = new ScreenLine(leftTokens, @text.substring(0, column))
rightLine = new ScreenLine(rightTokens, @text.substring(column))
[leftLine, rightLine]
splitTokenAt: (token, splitIndex) ->
{ type, value } = token
value1 = value.substring(0, splitIndex)
value2 = value.substring(splitIndex)
[{value: value1, type }, {value: value2, type}]