mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Add clipScreenPosition to LineFolder & LineMap
This commit is contained in:
@@ -136,6 +136,9 @@ class LineFolder
|
||||
bufferPositionForScreenPosition: (screenPosition) ->
|
||||
@lineMap.bufferPositionForScreenPosition(screenPosition)
|
||||
|
||||
clipScreenPosition: (screenPosition) ->
|
||||
@lineMap.clipScreenPosition(screenPosition)
|
||||
|
||||
screenRangeForBufferRange: (bufferRange) ->
|
||||
@lineMap.screenRangeForBufferRange(bufferRange)
|
||||
|
||||
|
||||
@@ -135,3 +135,18 @@ class LineMap
|
||||
end = @screenPositionForBufferPosition(bufferRange.end)
|
||||
new Range(start, end)
|
||||
|
||||
clipScreenPosition: (screenPosition) ->
|
||||
screenPosition = Point.fromObject(screenPosition)
|
||||
screenPosition = new Point(Math.max(0, screenPosition.row), Math.max(0, screenPosition.column))
|
||||
|
||||
screenDelta = new Point
|
||||
for screenLine in @screenLines
|
||||
nextDelta = screenDelta.add(screenLine.screenDelta)
|
||||
break if nextDelta.isGreaterThan(screenPosition)
|
||||
screenDelta = nextDelta
|
||||
|
||||
maxColumn = screenDelta.column + screenLine.lengthForClipping()
|
||||
screenDelta.column = Math.min(maxColumn, screenPosition.column)
|
||||
|
||||
screenDelta
|
||||
|
||||
|
||||
Reference in New Issue
Block a user