Skip to content

Commit 251033a

Browse files
committed
Only Highlight Visible Range
1 parent d28d9b0 commit 251033a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Sources/CodeEditTextView/TextSelectionManager/TextSelectionManager+FillRects.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ extension TextSelectionManager {
1919
/// - textSelection: The selection to use.
2020
/// - Returns: An array of rects that the selection overlaps.
2121
func getFillRects(in rect: NSRect, for textSelection: TextSelection) -> [CGRect] {
22-
guard let layoutManager else { return [] }
23-
let range = textSelection.range
22+
guard let layoutManager,
23+
let range = textSelection.range.intersection(textView?.visibleTextRange ?? .zero) else {
24+
return []
25+
}
2426

2527
var fillRects: [CGRect] = []
2628

@@ -33,7 +35,7 @@ extension TextSelectionManager {
3335
}
3436

3537
// Pixel align these to avoid aliasing on the edges of each rect that should be a solid box.
36-
return fillRects.map { $0.intersection(insetRect).pixelAligned }
38+
return fillRects.map { $0.pixelAligned }
3739
}
3840

3941
/// Find fill rects for a specific line position.

0 commit comments

Comments
 (0)