diff --git a/Sources/CodeEditTextView/TextLine/Typesetter/Typesetter.swift b/Sources/CodeEditTextView/TextLine/Typesetter/Typesetter.swift index b5edb859..f79bf9a6 100644 --- a/Sources/CodeEditTextView/TextLine/Typesetter/Typesetter.swift +++ b/Sources/CodeEditTextView/TextLine/Typesetter/Typesetter.swift @@ -181,7 +181,9 @@ final public class Typesetter { ) // Indicates the subrange on the range that the typesetter knows about. This may not be the entire line - let typesetSubrange = NSRange(location: context.currentPosition - range.location, length: lineBreak) + // Convert the absolute position to an offset relative to the typesetter's range. + let startOffset = context.currentPosition - range.location + let typesetSubrange = NSRange(location: startOffset, length: lineBreak - startOffset) let typesetData = typesetLine(typesetter: typesetter, range: typesetSubrange) // The typesetter won't tell us if 0 characters can fit in the constrained space. This checks to