Fix highlight end pixel position calculation

Previously, we were calculating the position preceding block decorations
for the row following the end of the highlighted range, but that's
actually wrong. We just want the position following block decorations of
the end of the highlighted range, plus one line height. This prevents us
from incorrectly rendering the end of highlight after block decorations
that immediately follow the end of the highlighted range.
This commit is contained in:
Nathan Sobo
2017-08-18 20:53:58 -06:00
parent be3dbab491
commit f33051da33
2 changed files with 17 additions and 1 deletions

View File

@@ -1697,6 +1697,22 @@ describe('TextEditorComponent', () => {
await component.getNextUpdatePromise()
expect(Array.from(marker1Region.parentElement.children).indexOf(marker1Region)).toBe(0)
})
it('correctly positions highlights that end on rows preceding block decorations', async () => {
const {editor, element, component} = buildComponent()
const item = document.createElement('div')
item.style.height = '30px'
editor.decorateMarker(editor.markBufferPosition([4, 0]), {
type: 'block', position: 'after', item
})
editor.setSelectedBufferRange([[3, 0], [4, Infinity]])
await component.getNextUpdatePromise()
const regions = element.querySelectorAll('.selection .region')
expect(regions[0].offsetTop).toBe(3 * component.getLineHeight())
expect(regions[1].offsetTop).toBe(4 * component.getLineHeight())
})
})
describe('overlay decorations', () => {

View File

@@ -1316,7 +1316,7 @@ class TextEditorComponent {
const {start, end} = highlight.screenRange
highlight.startPixelTop = this.pixelPositionAfterBlocksForRow(start.row)
highlight.startPixelLeft = this.pixelLeftForRowAndColumn(start.row, start.column)
highlight.endPixelTop = this.pixelPositionBeforeBlocksForRow(end.row + 1)
highlight.endPixelTop = this.pixelPositionBeforeBlocksForRow(end.row) + this.getLineHeight()
highlight.endPixelLeft = this.pixelLeftForRowAndColumn(end.row, end.column)
}
this.decorationsToRender.highlights.set(tileRow, highlights)