From 835ed10f7c25b7e808f36ce77b5175169965eb6a Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sun, 20 Aug 2017 07:32:44 -0600 Subject: [PATCH] Handle highlight end rows with 'before' blocks in addition to 'after' --- spec/text-editor-component-spec.js | 26 ++++++++++++++++++-------- src/text-editor-component.js | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index 1c37c549d..36576c877 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -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) }) }) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index 3c9e5b569..5ca04ea04 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -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)