From eb33e4fc76899ced10866743490903eec0b49497 Mon Sep 17 00:00:00 2001 From: Matias Korhonen Date: Sat, 14 Mar 2026 17:56:01 +0200 Subject: [PATCH 1/2] Fix Word Duplication at Wrap Boundaries suggestLineBreak returns a position in the string, but it was passed directly as a length to NSRange. On the first fragment this works by coincidence (position equals length when starting at 0), but on subsequent fragments the length is too large by startOffset, causing each CTLine to include characters already rendered in the previous fragment. Co-Authored-By: Claude Opus 4.6 --- Sources/CodeEditTextView/TextLine/Typesetter/Typesetter.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/CodeEditTextView/TextLine/Typesetter/Typesetter.swift b/Sources/CodeEditTextView/TextLine/Typesetter/Typesetter.swift index b5edb859..ccd236ee 100644 --- a/Sources/CodeEditTextView/TextLine/Typesetter/Typesetter.swift +++ b/Sources/CodeEditTextView/TextLine/Typesetter/Typesetter.swift @@ -181,7 +181,8 @@ 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) + 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 From 092ab9cbb7692986c706c9ea5b67e5be5670ab62 Mon Sep 17 00:00:00 2001 From: Matias Korhonen Date: Sat, 14 Mar 2026 18:03:54 +0200 Subject: [PATCH 2/2] Add comment for startOffset in layoutTextUntilLineBreak Co-Authored-By: Claude Opus 4.6 --- Sources/CodeEditTextView/TextLine/Typesetter/Typesetter.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/CodeEditTextView/TextLine/Typesetter/Typesetter.swift b/Sources/CodeEditTextView/TextLine/Typesetter/Typesetter.swift index ccd236ee..f79bf9a6 100644 --- a/Sources/CodeEditTextView/TextLine/Typesetter/Typesetter.swift +++ b/Sources/CodeEditTextView/TextLine/Typesetter/Typesetter.swift @@ -181,6 +181,7 @@ final public class Typesetter { ) // Indicates the subrange on the range that the typesetter knows about. This may not be the entire line + // 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)