From 245139c7bdb3eff4fed81eec02683a16f0eb28f4 Mon Sep 17 00:00:00 2001 From: Khan Winter <35942988+thecoolwinter@users.noreply.github.com> Date: Mon, 17 Jun 2024 20:02:40 -0500 Subject: [PATCH] Fix Cursor Height=0 At End Of Doc --- .../TextSelectionManager/TextSelectionManager.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/CodeEditTextView/TextSelectionManager/TextSelectionManager.swift b/Sources/CodeEditTextView/TextSelectionManager/TextSelectionManager.swift index bcd2ddead..106255f62 100644 --- a/Sources/CodeEditTextView/TextSelectionManager/TextSelectionManager.swift +++ b/Sources/CodeEditTextView/TextSelectionManager/TextSelectionManager.swift @@ -233,12 +233,15 @@ public class TextSelectionManager: NSObject { /// - Parameter range: The range the cursor is at. /// - Returns: The height the cursor should be to match the text at that location. fileprivate func heightForCursorAt(_ range: NSRange) -> CGFloat? { - let selectedLine = layoutManager?.textLineForOffset(range.location) - return selectedLine? + guard let selectedLine = layoutManager?.textLineForOffset(range.location) else { + return layoutManager?.estimateLineHeight() + } + return selectedLine .data .lineFragments - .getLine(atOffset: range.location - (selectedLine?.range.location ?? 0))? + .getLine(atOffset: range.location - (selectedLine.range.location))? .height + ?? layoutManager?.estimateLineHeight() }