Handle highlight end rows with 'before' blocks in addition to 'after'

This commit is contained in:
Nathan Sobo
2017-08-20 07:32:44 -06:00
parent f33051da33
commit 835ed10f7c
2 changed files with 19 additions and 9 deletions

View File

@@ -1698,20 +1698,30 @@ describe('TextEditorComponent', () => {
expect(Array.from(marker1Region.parentElement.children).indexOf(marker1Region)).toBe(0)
})
it('correctly positions highlights that end on rows preceding block decorations', async () => {
it('correctly positions highlights that end on rows preceding or following block decorations', async () => {
const {editor, element, component} = buildComponent()
const item = document.createElement('div')
item.style.height = '30px'
const item1 = document.createElement('div')
item1.style.height = '30px'
item1.style.backgroundColor = 'blue'
editor.decorateMarker(editor.markBufferPosition([4, 0]), {
type: 'block', position: 'after', item
type: 'block', position: 'after', item: item1
})
const item2 = document.createElement('div')
item2.style.height = '30px'
item2.style.backgroundColor = 'yellow'
editor.decorateMarker(editor.markBufferPosition([4, 0]), {
type: 'block', position: 'before', item: item2
})
editor.decorateMarker(editor.markBufferRange([[3, 0], [4, Infinity]]), {
type: 'highlight', class: 'highlight'
})
editor.setSelectedBufferRange([[3, 0], [4, Infinity]])
await component.getNextUpdatePromise()
const regions = element.querySelectorAll('.selection .region')
await component.getNextUpdatePromise()
const regions = element.querySelectorAll('.highlight .region')
expect(regions[0].offsetTop).toBe(3 * component.getLineHeight())
expect(regions[1].offsetTop).toBe(4 * component.getLineHeight())
expect(regions[0].offsetHeight).toBe(component.getLineHeight())
expect(regions[1].offsetTop).toBe(4 * component.getLineHeight() + 30)
})
})

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) + this.getLineHeight()
highlight.endPixelTop = this.pixelPositionAfterBlocksForRow(end.row) + this.getLineHeight()
highlight.endPixelLeft = this.pixelLeftForRowAndColumn(end.row, end.column)
}
this.decorationsToRender.highlights.set(tileRow, highlights)