Fix out-of-index crash by guarding against a 0-length string.

This commit is contained in:
Brent Simmons 2020-11-06 17:03:20 -08:00
parent 69911bd914
commit e297a53eb2
1 changed files with 4 additions and 1 deletions

View File

@ -53,7 +53,10 @@ final class MultilineTextFieldSizer {
}
static func size(for attributedString: NSAttributedString, numberOfLines: Int, width: Int) -> TextFieldSizeInfo {
guard attributedString.length > 0 else {
return TextFieldSizeInfo(size: NSSize.zero, numberOfLinesUsed: 0)
}
// Assumes the same font family/size for the whole string
let font = attributedString.attribute(.font, at: 0, effectiveRange: nil) as! NSFont