Merge pull request #13350 from atom/mb-fix-highlights-on-horizontal-scroll

Fix highlight movement when horizontally scrolling
This commit is contained in:
Max Brunsfeld
2016-11-29 09:30:08 -08:00
committed by GitHub
2 changed files with 25 additions and 4 deletions

View File

@@ -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]],

View File

@@ -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 = []