@@ -23,38 +23,13 @@ extension TextSelectionManager {
2323 let range = textSelection. range
2424
2525 var fillRects : [ CGRect ] = [ ]
26- guard let firstLinePosition = layoutManager. lineStorage. getLine ( atOffset: range. location) ,
27- let lastLinePosition = range. max == layoutManager. lineStorage. length
28- ? layoutManager. lineStorage. last
29- : layoutManager. lineStorage. getLine ( atOffset: range. max) else {
30- return [ ]
31- }
3226
3327 let insetXPos = max ( edgeInsets. left, rect. minX)
3428 let insetWidth = max ( 0 , rect. maxX - insetXPos - edgeInsets. right)
3529 let insetRect = NSRect ( x: insetXPos, y: rect. origin. y, width: insetWidth, height: rect. height)
3630
37- // Calculate the first line and any rects selected
38- // If the last line position is not the same as the first, calculate any rects from that line.
39- // If there's > 0 space between the first and last positions, add a rect between them to cover any
40- // intermediate lines.
41-
42- let firstLineRects = getFillRects ( in: rect, selectionRange: range, forPosition: firstLinePosition)
43- let lastLineRects : [ CGRect ] = if lastLinePosition. range != firstLinePosition. range {
44- getFillRects ( in: rect, selectionRange: range, forPosition: lastLinePosition)
45- } else {
46- [ ]
47- }
48-
49- fillRects. append ( contentsOf: firstLineRects + lastLineRects)
50-
51- if firstLinePosition. yPos + firstLinePosition. height < lastLinePosition. yPos {
52- fillRects. append ( CGRect (
53- x: insetXPos,
54- y: firstLinePosition. yPos + firstLinePosition. height,
55- width: insetWidth,
56- height: lastLinePosition. yPos - ( firstLinePosition. yPos + firstLinePosition. height)
57- ) )
31+ for linePosition in layoutManager. lineStorage. linesInRange ( range) {
32+ fillRects. append ( contentsOf: getFillRects ( in: insetRect, selectionRange: range, forPosition: linePosition) )
5833 }
5934
6035 // Pixel align these to avoid aliasing on the edges of each rect that should be a solid box.
0 commit comments