This commit is contained in:
Nathan Sobo 2012-02-22 17:36:38 -07:00
parent 237c03be7b
commit 5bb539df27
5 changed files with 51 additions and 57 deletions

View File

@ -22,10 +22,10 @@ describe "LineMap", ->
map.insertAtBufferRow(2, line3)
map.insertAtBufferRow(2, line2)
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.lineForScreenRow(0)).toEqual line0
expect(map.lineForScreenRow(1)).toEqual line1
expect(map.lineForScreenRow(2)).toEqual line2
expect(map.lineForScreenRow(3)).toEqual line3
describe "when passed an array of line fragments", ->
it "inserts the given line fragments before the specified buffer row", ->
@ -33,11 +33,11 @@ describe "LineMap", ->
map.insertAtBufferRow(0, [line0, line1])
map.insertAtBufferRow(4, [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]
expect(map.lineForScreenRow(0)).toEqual line0
expect(map.lineForScreenRow(1)).toEqual line1
expect(map.lineForScreenRow(2)).toEqual line2
expect(map.lineForScreenRow(3)).toEqual line3
expect(map.lineForScreenRow(4)).toEqual line4
describe ".spliceAtBufferRow(bufferRow, rowCount, screenLines)", ->
describe "when called with a row count of 0", ->
@ -45,11 +45,11 @@ describe "LineMap", ->
map.insertAtBufferRow(0, [line0, line1, line2])
map.spliceAtBufferRow(1, 0, [line3, line4])
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]
expect(map.lineForScreenRow(0)).toEqual line0
expect(map.lineForScreenRow(1)).toEqual line3
expect(map.lineForScreenRow(2)).toEqual line4
expect(map.lineForScreenRow(3)).toEqual line1
expect(map.lineForScreenRow(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.screenLinesForScreenRow(0)).toEqual [line0]
expect(map.screenLinesForScreenRow(1)).toEqual [line3]
expect(map.screenLinesForScreenRow(2)).toEqual [line4]
expect(map.screenLinesForScreenRow(3)).toEqual [line2]
expect(map.lineForScreenRow(0)).toEqual line0
expect(map.lineForScreenRow(1)).toEqual line3
expect(map.lineForScreenRow(2)).toEqual line4
expect(map.lineForScreenRow(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.screenLinesForScreenRow(0)).toEqual [line0]
expect(map.screenLinesForScreenRow(1)).toEqual [line3a, line3b]
expect(map.screenLinesForScreenRow(2)).toEqual [line4]
expect(map.screenLinesForScreenRow(3)).toEqual [line2]
expect(map.lineForScreenRow(0)).toEqual line0
expect(map.lineForScreenRow(1)).toEqual line3a.concat(line3b)
expect(map.lineForScreenRow(2)).toEqual line4
expect(map.lineForScreenRow(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.screenLinesForScreenRow(0)).toEqual [line0]
expect(map.screenLinesForScreenRow(1)).toEqual [line3a, line3b]
expect(map.screenLinesForScreenRow(2)).toEqual [line4]
expect(map.lineForScreenRow(0)).toEqual line0
expect(map.lineForScreenRow(1)).toEqual line3a.concat(line3b)
expect(map.lineForScreenRow(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.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]
expect(map.lineForScreenRow(0)).toEqual line0
expect(map.lineForScreenRow(1)).toEqual line3
expect(map.lineForScreenRow(2)).toEqual line4
expect(map.lineForScreenRow(3)).toEqual line1
expect(map.lineForScreenRow(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.screenLinesForScreenRow(0)).toEqual [line0]
expect(map.screenLinesForScreenRow(1)).toEqual [line3]
expect(map.screenLinesForScreenRow(2)).toEqual [line4]
expect(map.screenLinesForScreenRow(3)).toEqual [line2]
expect(map.lineForScreenRow(0)).toEqual line0
expect(map.lineForScreenRow(1)).toEqual line3
expect(map.lineForScreenRow(2)).toEqual line4
expect(map.lineForScreenRow(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.screenLinesForScreenRow(0)).toEqual [line0]
expect(map.screenLinesForScreenRow(1)).toEqual [line3a, line3b]
expect(map.screenLinesForScreenRow(2)).toEqual [line4]
expect(map.screenLinesForScreenRow(3)).toEqual [line2]
expect(map.lineForScreenRow(0)).toEqual line0
expect(map.lineForScreenRow(1)).toEqual line3a.concat(line3b)
expect(map.lineForScreenRow(2)).toEqual line4
expect(map.lineForScreenRow(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.screenLinesForScreenRow(0)).toEqual [line0]
expect(map.screenLinesForScreenRow(1)).toEqual [line3a, line3b]
expect(map.screenLinesForScreenRow(2)).toEqual [line4]
expect(map.lineForScreenRow(0)).toEqual line0
expect(map.lineForScreenRow(1)).toEqual line3a.concat(line3b)
expect(map.lineForScreenRow(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

@ -129,7 +129,7 @@ class Editor extends View
renderLines: ->
@lines.empty()
for screenLine in @lineWrapper.lines()
for screenLine in @lineWrapper.getLines()
@lines.append @buildLineElement(screenLine)
setBuffer: (@buffer) ->

View File

@ -80,6 +80,12 @@ class LineFolder
linesForScreenRows: (startRow, endRow) ->
@lineMap.linesForScreenRows(startRow, endRow)
getLines: ->
@lineMap.getScreenLines()
lineCount: ->
@lineMap.screenLineCount()
screenRowForBufferRow: (bufferRow) ->
@screenPositionForBufferPosition([bufferRow, 0]).row

View File

@ -45,26 +45,14 @@ class LineMap
replaceBufferRows: (start, end, screenLines) ->
@spliceAtBufferRow(start, end - start + 1, screenLines)
replaceScreenRow: (row, screenLines) ->
@replaceScreenRows(row, row, screenLines)
replaceScreenRows: (start, end, screenLines) ->
@spliceAtScreenRow(start, end - start + 1, screenLines)
screenLinesForScreenRow: (screenRow) ->
@screenLinesForScreenRows(screenRow, screenRow)
screenLinesForScreenRows: (startRow, endRow) ->
screenLines = []
delta = new Delta
for screenLine in @screenLines
break if delta.rows > endRow
screenLines.push(screenLine) if delta.rows >= startRow
delta = delta.add(screenLine.screenDelta)
screenLines
getScreenLines: ->
return @screenLines
lineForScreenRow: (row) ->
@linesForScreenRows(row, row)[0]

View File

@ -92,7 +92,7 @@ class LineWrapper
linesForScreenRows: (startRow, endRow) ->
@lineMap.linesForScreenRows(startRow, endRow)
lines: ->
getLines: ->
@linesForScreenRows(0, @lineCount() - 1)
lineCount: ->