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

Commit

Permalink
Fix skipping more empty boundaries than the size of the query
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Scandurra committed May 3, 2017
1 parent ec5eed7 commit e021171
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
21 changes: 15 additions & 6 deletions spec/marker-text-decoration-layer-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,16 @@ describe('MarkerTextDecorationLayer', () => {
it('fetches boundaries as needed based on the boundariesPerQuery parameter', () => {
const buffer = new TextBuffer({text: 'abcdef\n'.repeat(20)})
const markerLayer = buffer.addMarkerLayer()
markerLayer.markRange([[0, 2], [1, 2]])
markerLayer.markRange([[2, 2], [3, 2]])
markerLayer.markRange([[3, 2], [4, 2]])
markerLayer.markRange([[10, 2], [11, 2]])
markerLayer.markRange([[12, 2], [13, 2]])
const marker1 = markerLayer.markRange([[0, 2], [1, 2]])
const marker2 = markerLayer.markRange([[2, 2], [3, 2]])
const marker3 = markerLayer.markRange([[3, 2], [4, 2]])
const marker4 = markerLayer.markRange([[10, 2], [11, 2]])
const marker5 = markerLayer.markRange([[12, 2], [13, 2]])

const decoratedMarkerIds = new Set([marker1.id, marker2.id, marker3.id, marker4.id, marker5.id])
const textDecorationLayer = new MarkerTextDecorationLayer(markerLayer, {
boundariesPerQuery: 3,
classNameForMarkerId: () => 'foo'
classNameForMarkerId: (markerId) => decoratedMarkerIds.has(markerId) ? 'foo' : null
})

const iterator = textDecorationLayer.buildIterator()
Expand All @@ -133,6 +134,14 @@ describe('MarkerTextDecorationLayer', () => {
expect(iterator.getPosition()).toEqual(Point(12, 2))
iterator.moveToSuccessor()
expect(iterator.getPosition()).toEqual(Point(13, 2))

// Ensure skipping more empty boundaries than the size of the query works correctly.
decoratedMarkerIds.delete(marker1.id)
decoratedMarkerIds.delete(marker2.id)
iterator.seek(Point(0, 0))
expect(iterator.getPosition()).toEqual(Point(3, 2))
iterator.moveToSuccessor()
expect(iterator.getPosition()).toEqual(Point(4, 2))
})
})

Expand Down
29 changes: 15 additions & 14 deletions src/marker-text-decoration-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,24 @@ class MarkerTextDecorationLayerIterator {
}

moveToSuccessor () {
if (this.boundaryIndex === this.boundaries.length) return

// Fetch more marker boundaries if needed
if (this.boundaryIndex === this.boundaries.length - 1) {
const {row, column} = this.getPosition()
const {boundaries} = this.layer.markerLayer.index.findBoundariesAfter(
Point(row, column + 1),
this.layer.boundariesPerQuery
)
this.boundaries = boundaries
this.boundaryIndex = -1
}
if (this.boundaries.length === 0) return

do {
this.boundaryIndex++
// Fetch more marker boundaries if needed
if (this.boundaryIndex === this.boundaries.length - 1) {
const {row, column} = this.getPosition()
const {boundaries} = this.layer.markerLayer.index.findBoundariesAfter(
Point(row, column + 1),
this.layer.boundariesPerQuery
)
this.boundaries = boundaries
this.boundaryIndex = 0
} else {
this.boundaryIndex++
}

this.computeScopeIds()
} while (this.openScopeIds.length === 0 && this.closeScopeIds.length === 0 && this.boundaryIndex < this.boundaries.length)
} while (this.openScopeIds.length === 0 && this.closeScopeIds.length === 0 && this.boundaries.length > 0)
}

getPosition () {
Expand Down

0 comments on commit e021171

Please sign in to comment.