Allow the screen row count of N-screen:1-buffer mappings to be updated

This commit is contained in:
Nathan Sobo
2013-05-07 17:56:09 -06:00
parent 5c74a02688
commit 1895e8143d
2 changed files with 24 additions and 1 deletions

View File

@@ -144,3 +144,20 @@ describe "RowMap", ->
expect(map.bufferRowRangeForScreenRow(23)).toEqual [20, 21]
expect(map.bufferRowRangeForScreenRow(27)).toEqual [20, 21]
expect(map.bufferRowRangeForScreenRow(28)).toEqual [21, 22]
describe "after re-mapping a row range to a new number of screen rows", ->
beforeEach ->
map.mapBufferRowRange(10, 11, 4)
it "updates translation accordingly", ->
expect(map.screenRowRangeForBufferRow(4)).toEqual [4, 5]
expect(map.screenRowRangeForBufferRow(5)).toEqual [5, 8]
expect(map.screenRowRangeForBufferRow(6)).toEqual [8, 9]
expect(map.screenRowRangeForBufferRow(9)).toEqual [11, 12]
expect(map.screenRowRangeForBufferRow(10)).toEqual [12, 16]
expect(map.screenRowRangeForBufferRow(11)).toEqual [16, 17]
expect(map.screenRowRangeForBufferRow(19)).toEqual [24, 25]
expect(map.screenRowRangeForBufferRow(20)).toEqual [25, 30]
expect(map.screenRowRangeForBufferRow(21)).toEqual [30, 31]

View File

@@ -21,7 +21,13 @@ class RowMap
mapBufferRowRange: (startBufferRow, endBufferRow, screenRows) ->
{ mapping, index, bufferRow } = @traverseToBufferRow(startBufferRow)
throw new Error("Invalid mapping insertion") if mapping and mapping.bufferRows != mapping.screenRows
if mapping and mapping.bufferRows != mapping.screenRows
if bufferRow == startBufferRow and bufferRow + mapping.bufferRows == endBufferRow
mapping.screenRows = screenRows
return
else
throw new Error("Invalid mapping insertion")
padBefore = startBufferRow - bufferRow
padAfter = (bufferRow + mapping?.bufferRows) - endBufferRow