diff --git a/spec/display-layer-spec.js b/spec/display-layer-spec.js index fdac1aefb5..c5a02f05b5 100644 --- a/spec/display-layer-spec.js +++ b/spec/display-layer-spec.js @@ -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', () => { diff --git a/src/display-layer.js b/src/display-layer.js index 2f07426f31..0e36fa1469 100644 --- a/src/display-layer.js +++ b/src/display-layer.js @@ -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 } } }