Skip to content

Commit 586943f

Browse files
committed
Fix prepareContent() crash with negative origin
The prepareContent(in:) method could crash if the inset rectangle had a negative origin. This change ensures the inset rectangle's origin is never negative by clamping the x and y values to a minimum of 0.
1 parent 1f164cb commit 586943f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Sources/STTextViewAppKit/STTextView.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,9 @@ import AVFoundation
824824
}
825825

826826
open override func prepareContent(in rect: NSRect) {
827-
super.prepareContent(in: rect.inset(dy: -visibleRect.height / 2))
827+
var insetRect = rect.inset(dy: -visibleRect.height / 2)
828+
insetRect.origin = CGPoint(x: max(0, insetRect.origin.x), y: max(insetRect.origin.y, 0))
829+
super.prepareContent(in: insetRect)
828830
layoutViewport()
829831
}
830832

0 commit comments

Comments
 (0)