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

Commit

Permalink
Fix preceding boundary calculation for changes inside of folds
Browse files Browse the repository at this point in the history
If a change is inside a fold and that fold appears at the beginning of a
soft-wrapped line segment, we need to continue iterating upward in our
search for a line boundary. Previously we would stop because the screen
column was 0, but that is invalid if the beginning of the buffer row
isn't on screen due to being folded.

Signed-off-by: Antonio Scandurra <as-cii@github.com>
  • Loading branch information
Nathan Sobo authored and Antonio Scandurra committed Feb 16, 2017
1 parent 2e9b8ad commit cf55378
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 cf55378

Please sign in to comment.