mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Merge adjacent isomorphic regions after adding new regions
This commit is contained in:
parent
d9c258f27e
commit
b4c95d4fc9
@ -187,6 +187,13 @@ describe "RowMap", ->
|
||||
expect(map.regions[2]).toEqual(bufferRows: 3, screenRows: 8)
|
||||
expect(map.regions[3]).toEqual(bufferRows: 2, screenRows: 1)
|
||||
|
||||
it "merges adjacent isomorphic mappings", ->
|
||||
map.mapBufferRowRange(2, 4, 1)
|
||||
map.mapBufferRowRange(4, 5, 2)
|
||||
|
||||
map.mapBufferRowRange(1, 4, 3)
|
||||
expect(map.regions).toEqual [{bufferRows: 5, screenRows: 5}]
|
||||
|
||||
describe ".applyBufferDelta(startBufferRow, delta)", ->
|
||||
describe "when applying a positive delta", ->
|
||||
it "expands the region containing the given start row by the given delta", ->
|
||||
|
@ -94,6 +94,20 @@ class RowMap
|
||||
newRegions.push(bufferRows: overlapEndBufferRow - endBufferRow, screenRows: overlapEndScreenRow - endScreenRow)
|
||||
|
||||
@regions[overlapStartIndex..overlapEndIndex] = newRegions
|
||||
@mergeIsomorphicRegions(Math.max(0, overlapStartIndex - 1), Math.min(@regions.length - 1, overlapEndIndex + 1))
|
||||
|
||||
mergeIsomorphicRegions: (startIndex, endIndex) ->
|
||||
return if startIndex == endIndex
|
||||
|
||||
region = @regions[startIndex]
|
||||
nextRegion = @regions[startIndex + 1]
|
||||
if region.bufferRows == region.screenRows and nextRegion.bufferRows == nextRegion.screenRows
|
||||
@regions[startIndex..startIndex + 1] =
|
||||
bufferRows: region.bufferRows + nextRegion.bufferRows
|
||||
screenRows: region.screenRows + nextRegion.screenRows
|
||||
@mergeIsomorphicRegions(startIndex, endIndex - 1)
|
||||
else
|
||||
@mergeIsomorphicRegions(startIndex + 1, endIndex)
|
||||
|
||||
# This method records insertion or removal of rows in the buffer, adjusting the
|
||||
# buffer dimension of regions following the start row accordingly.
|
||||
|
Loading…
Reference in New Issue
Block a user