Fix bug in LineMap.spliceByDelta with multi-fragment screen lines

If the row following a row being replaced had multiple fragments, some
of these fragments would be accidentally deleted.
This commit is contained in:
Nathan Sobo
2012-03-01 11:52:27 -07:00
parent 32a6a2cd7f
commit eb0df2f21d
2 changed files with 17 additions and 2 deletions

View File

@@ -61,6 +61,10 @@ describe "LineMap", ->
expect(map.lineForOutputRow(2)).toEqual line4
expect(map.lineForOutputRow(3)).toEqual line2
map.spliceAtInputRow(2, 1, [line0])
expect(map.lineForOutputRow(2)).toEqual line0
expect(map.lineForOutputRow(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", ->
[line1a, line1b] = line1.splitAt(10)
@@ -75,6 +79,18 @@ describe "LineMap", ->
expect(map.lineForOutputRow(2)).toEqual line4
expect(map.lineForOutputRow(3)).toEqual line2
describe "when the row following the specified buffer row is spanned by multiple line fragments", ->
it "replaces the specified row, but no portion of the following row", ->
[line3a, line3b] = line3.splitAt(10)
map.insertAtInputRow(0, [line0, line1, line2, line3a, line3b])
map.spliceAtInputRow(2, 1, [line4])
expect(map.lineForOutputRow(0)).toEqual line0
expect(map.lineForOutputRow(1)).toEqual line1
expect(map.lineForOutputRow(2)).toEqual line4
expect(map.lineForOutputRow(3)).toEqual line3a.concat(line3b)
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", ->
[line1a, line1b] = line1.splitAt(10)

View File

@@ -76,9 +76,8 @@ class LineMap
delta = new Point
for lineFragment, i in @lineFragments
startIndex ?= i if delta.row == startRow
break if rowCount == 0 and delta.row == stopRow
break if delta.row == stopRow
delta = delta.add(lineFragment[deltaType])
break if delta.row > stopRow
stopIndex++
startIndex ?= i