From 1895e8143d7868ffca41cd0644339614a9cdbd89 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 7 May 2013 17:56:09 -0600 Subject: [PATCH] Allow the screen row count of N-screen:1-buffer mappings to be updated --- spec/app/row-map-spec.coffee | 17 +++++++++++++++++ src/app/row-map.coffee | 8 +++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/app/row-map-spec.coffee b/spec/app/row-map-spec.coffee index 96ac3dbde..51d2392dd 100644 --- a/spec/app/row-map-spec.coffee +++ b/spec/app/row-map-spec.coffee @@ -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] diff --git a/src/app/row-map.coffee b/src/app/row-map.coffee index ca676b334..caa0bfda5 100644 --- a/src/app/row-map.coffee +++ b/src/app/row-map.coffee @@ -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