mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
🐛 Fix incorrectly reported width when measuring lines
This commit fixes what seems to be a bug in Chromium. When measuring lines (and with a special character sequence), it could happen that Range(0, 0). getBoundingClientRect().width reports a number greater than 0. This seems to happen when the font size is smaller than 12px and it's probably due to subpixel font scaling. To solve it we've explicitly included a guard clause that prevents this problem to happen.
This commit is contained in:
@@ -159,9 +159,12 @@ class LinesYardstick
|
||||
0
|
||||
|
||||
leftPixelPositionForCharInTextNode: (lineNode, textNode, charIndex) ->
|
||||
@rangeForMeasurement.setStart(textNode, 0)
|
||||
@rangeForMeasurement.setEnd(textNode, charIndex)
|
||||
width = @rangeForMeasurement.getBoundingClientRect().width
|
||||
if charIndex is 0
|
||||
width = 0
|
||||
else
|
||||
@rangeForMeasurement.setStart(textNode, 0)
|
||||
@rangeForMeasurement.setEnd(textNode, charIndex)
|
||||
width = @rangeForMeasurement.getBoundingClientRect().width
|
||||
|
||||
@rangeForMeasurement.setStart(textNode, 0)
|
||||
@rangeForMeasurement.setEnd(textNode, textNode.textContent.length)
|
||||
|
||||
Reference in New Issue
Block a user