From 7cd1833a17ccd81719c69d9b134a35939eb267cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=B8vring?= Date: Wed, 12 Oct 2022 07:32:38 +0200 Subject: [PATCH] closestIndex(to:) returns beginning of line if line fragment is unavailable (#218) --- Sources/Runestone/TextView/LineController/LineController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Runestone/TextView/LineController/LineController.swift b/Sources/Runestone/TextView/LineController/LineController.swift index 0539c61e6..eb518293e 100644 --- a/Sources/Runestone/TextView/LineController/LineController.swift +++ b/Sources/Runestone/TextView/LineController/LineController.swift @@ -447,7 +447,7 @@ extension LineController { func closestIndex(to point: CGPoint) -> Int { guard let closestLineFragment = lineFragment(closestTo: point) else { - return 0 + return line.location } let localLocation = min(CTLineGetStringIndexForPosition(closestLineFragment.line, point), line.data.length) return line.location + localLocation