diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index 9eb4a15d2..629a7ae58 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -2028,6 +2028,27 @@ describe "TextEditorPresenter", -> expect(stateForHighlightInTile(presenter, highlight, 0)).toBeUndefined() + it "handles highlights that extend to the left of the visible area (regression)", -> + editor.setSelectedBufferRanges([ + [[0, 2], [1, 4]], + ]) + + presenter = buildPresenter(explicitHeight: 20, scrollLeft: 0, tileSize: 2) + expectValues stateForSelectionInTile(presenter, 0, 0), { + regions: [ + {top: 0 * 10, height: 10, left: 2 * 10, right: 0 * 10}, + {top: 1 * 10, height: 10, left: 0 * 10, width: 4 * 10} + ] + } + + presenter = buildPresenter(explicitHeight: 20, scrollLeft: 20, tileSize: 2) + expectValues stateForSelectionInTile(presenter, 0, 0), { + regions: [ + {top: 0 * 10, height: 10, left: 2 * 10, right: 0 * 10}, + {top: 1 * 10, height: 10, left: 0 * 10, width: 4 * 10} + ] + } + it "updates when ::scrollTop changes", -> editor.setSelectedBufferRanges([ [[6, 2], [6, 4]], diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index cc988bbea..89c600515 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -1001,8 +1001,7 @@ class TextEditorPresenter @lineHeight? and @baseCharacterWidth? pixelPositionForScreenPosition: (screenPosition) -> - position = - @linesYardstick.pixelPositionForScreenPosition(screenPosition) + position = @linesYardstick.pixelPositionForScreenPosition(screenPosition) position.top -= @getScrollTop() position.left -= @getScrollLeft() @@ -1225,13 +1224,14 @@ class TextEditorPresenter screenRange.end.column = 0 repositionRegionWithinTile: (region, tileStartRow) -> - region.top += @scrollTop - @lineTopIndex.pixelPositionBeforeBlocksForRow(tileStartRow) - region.left += @scrollLeft + region.top += @scrollTop - @lineTopIndex.pixelPositionBeforeBlocksForRow(tileStartRow) buildHighlightRegions: (screenRange) -> lineHeightInPixels = @lineHeight startPixelPosition = @pixelPositionForScreenPosition(screenRange.start) endPixelPosition = @pixelPositionForScreenPosition(screenRange.end) + startPixelPosition.left += @scrollLeft + endPixelPosition.left += @scrollLeft spannedRows = screenRange.end.row - screenRange.start.row + 1 regions = []