Skip to content

Commit fafc65d

Browse files
committed
Fix word duplication at wrap boundaries
suggestLineBreak returns an absolute position, 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. Cherry-pick of CodeEditApp#122 Fixes CodeEditApp/CodeEditSourceEditor#367
1 parent d7ac3f1 commit fafc65d

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

Sources/CodeEditTextView/TextLine/Typesetter/Typesetter.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ final public class Typesetter {
181181
)
182182

183183
// Indicates the subrange on the range that the typesetter knows about. This may not be the entire line
184-
let typesetSubrange = NSRange(location: context.currentPosition - range.location, length: lineBreak)
184+
// Convert the absolute position to an offset relative to the typesetter's range.
185+
let startOffset = context.currentPosition - range.location
186+
let typesetSubrange = NSRange(location: startOffset, length: lineBreak - startOffset)
185187
let typesetData = typesetLine(typesetter: typesetter, range: typesetSubrange)
186188

187189
// The typesetter won't tell us if 0 characters can fit in the constrained space. This checks to

0 commit comments

Comments
 (0)