mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Slightly more precise conversion to screen positions
This commit is contained in:
@@ -35,7 +35,9 @@ class LinesYardstick
|
||||
return new Point(row, 0) unless lineNode? and line?
|
||||
|
||||
iterator = document.createNodeIterator(lineNode, NodeFilter.SHOW_TEXT)
|
||||
charIndex = 0
|
||||
column = 0
|
||||
previousColumn = 0
|
||||
previousDistance = Infinity
|
||||
|
||||
@tokenIterator.reset(line)
|
||||
while @tokenIterator.next()
|
||||
@@ -57,19 +59,23 @@ class LinesYardstick
|
||||
textNodeIndex = 0
|
||||
nextTextNodeIndex = textNodeLength
|
||||
|
||||
while nextTextNodeIndex <= charIndex
|
||||
while nextTextNodeIndex <= column
|
||||
textNode = iterator.nextNode()
|
||||
textNodeLength = textNode.textContent.length
|
||||
textNodeIndex = nextTextNodeIndex
|
||||
nextTextNodeIndex = textNodeIndex + textNodeLength
|
||||
|
||||
indexWithinTextNode = charIndex - textNodeIndex
|
||||
indexWithinTextNode = column - textNodeIndex
|
||||
left = @leftPixelPositionForCharInTextNode(lineNode, textNode, indexWithinTextNode)
|
||||
break if left >= targetLeft
|
||||
distance = Math.abs(targetLeft - left)
|
||||
|
||||
charIndex += charLength
|
||||
return new Point(row, previousColumn) if distance > previousDistance
|
||||
|
||||
new Point(row, charIndex)
|
||||
previousDistance = distance
|
||||
previousColumn = column
|
||||
column += charLength
|
||||
|
||||
new Point(row, column)
|
||||
|
||||
pixelPositionForScreenPosition: (screenPosition, clip=true) ->
|
||||
screenPosition = Point.fromObject(screenPosition)
|
||||
|
||||
Reference in New Issue
Block a user