Discard highlights that end above the visible row range

Fixes #9628
This commit is contained in:
Nathan Sobo
2015-11-17 11:45:51 -08:00
parent 192e804c8f
commit 8da44c4dfc
2 changed files with 30 additions and 8 deletions

View File

@@ -1704,6 +1704,18 @@ describe "TextEditorPresenter", ->
expectUndefinedStateForHighlight(presenter, highlight)
it "does not include highlights that end before the first visible row", ->
editor.setText("Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.")
editor.setSoftWrapped(true)
editor.setWidth(100, true)
editor.setDefaultCharWidth(10)
marker = editor.markBufferRange([[0, 0], [0, 4]], invalidate: 'never')
highlight = editor.decorateMarker(marker, type: 'highlight', class: 'a')
presenter = buildPresenter(explicitHeight: 30, scrollTop: 10, tileSize: 2)
expect(stateForHighlightInTile(presenter, highlight, 0)).toBeUndefined()
it "updates when ::scrollTop changes", ->
editor.setSelectedBufferRanges([
[[6, 2], [6, 4]],

View File

@@ -1244,14 +1244,7 @@ class TextEditorPresenter
updateHighlightState: (decorationId, properties, screenRange) ->
return unless @startRow? and @endRow? and @lineHeight? and @hasPixelPositionRequirements()
return if screenRange.isEmpty()
if screenRange.start.row < @startRow
screenRange.start.row = @startRow
screenRange.start.column = 0
if screenRange.end.row >= @endRow
screenRange.end.row = @endRow
screenRange.end.column = 0
@constrainRangeToVisibleRowRange(screenRange)
return if screenRange.isEmpty()
@@ -1281,6 +1274,23 @@ class TextEditorPresenter
true
constrainRangeToVisibleRowRange: (screenRange) ->
if screenRange.start.row < @startRow
screenRange.start.row = @startRow
screenRange.start.column = 0
if screenRange.end.row < @startRow
screenRange.end.row = @startRow
screenRange.end.column = 0
if screenRange.start.row >= @endRow
screenRange.start.row = @endRow
screenRange.start.column = 0
if screenRange.end.row >= @endRow
screenRange.end.row = @endRow
screenRange.end.column = 0
repositionRegionWithinTile: (region, tileStartRow) ->
region.top += @scrollTop - tileStartRow * @lineHeight
region.left += @scrollLeft