Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #212 from atom/ns-as-fix-preceding-boundary-search
Browse files Browse the repository at this point in the history
Fix preceding boundary calculation for changes inside of folds
  • Loading branch information
Nathan Sobo committed Feb 17, 2017
1 parent db4c08f commit fa44267
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
15 changes: 15 additions & 0 deletions spec/display-layer-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,21 @@ describe('DisplayLayer', () => {
}
}
})

it('correctly updates the index for edits fully contained within multi-line folds that appear on soft-wrapped line segments', () => {
const buffer = new TextBuffer({
text: 'premillennial alcoholism\nelse\t\nastraphobia stereotomy\nbananas\n'
})
const displayLayer = buffer.addDisplayLayer({
tabLength: 4,
invisibles: {eol: '¬'},
softWrapColumn: 10
})
displayLayer.foldBufferRange([[0, 16], [1, 4]])
displayLayer.foldBufferRange([[1, 5], [3, 3]])
buffer.setTextInRange([[2, 16], [2, 21]], ' \nunderlinen\ncopybook\t')
expect(displayLayer.getText()).toBe('premillenn\nial al⋯ \n⋯anas¬\n')
})
})

describe('soft wraps', () => {
Expand Down
13 changes: 5 additions & 8 deletions src/display-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -999,16 +999,13 @@ class DisplayLayer {

findBoundaryPrecedingBufferRow (bufferRow) {
while (true) {
if (bufferRow === 0) return 0
let screenPosition = this.translateBufferPositionWithSpatialIndex(Point(bufferRow, 0), 'backward')
if (screenPosition.column === 0) {
return this.translateScreenPositionWithSpatialIndex(screenPosition, 'backward').row
let bufferPosition = this.translateScreenPositionWithSpatialIndex(Point(screenPosition.row, 0), 'backward', false)
if (screenPosition.column === 0 && bufferPosition.column === 0) {
return bufferPosition.row
} else {
let bufferPosition = this.translateScreenPositionWithSpatialIndex(Point(screenPosition.row, 0), 'backward', false)
if (bufferPosition.column === 0) {
return bufferPosition.row
} else {
bufferRow = bufferPosition.row
}
bufferRow = bufferPosition.row
}
}
}
Expand Down

0 comments on commit fa44267

Please sign in to comment.