Skip to content

Commit

Permalink
Fix prepareContent() crash with negative origin
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
krzyzanowskim committed Jan 1, 2025
1 parent 1f164cb commit 586943f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Sources/STTextViewAppKit/STTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,9 @@ import AVFoundation
}

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

Expand Down

0 comments on commit 586943f

Please sign in to comment.