@@ -135,22 +135,20 @@ extension STTextView: UITextInput {
135
135
guard let position = position as? STTextLocation else {
136
136
return nil
137
137
}
138
- guard let textLayoutFragment = textLayoutManager. textLayoutFragment ( for: position. location) else {
139
- return nil
140
- }
141
- guard let textLineFragment = textLayoutFragment. textLineFragment ( at: position. location) else {
142
- return nil
138
+
139
+ let positionSelection = NSTextSelection ( position. location, affinity: . downstream)
140
+ var destination : NSTextSelection ? = positionSelection
141
+ for _ in 0 ..< offset {
142
+ destination = textLayoutManager. textSelectionNavigation. destinationSelection (
143
+ for: destination ?? positionSelection,
144
+ direction: direction. textSelectionNavigationDirection,
145
+ destination: . character,
146
+ extending: false ,
147
+ confined: false
148
+ )
143
149
}
144
- let characterOffset = textLayoutManager. offset ( from: textLayoutFragment. rangeInElement. location, to: position. location)
145
- let characterLocation = textLineFragment. locationForCharacter ( at: characterOffset)
146
- let originTextSelection = NSTextSelection ( position. location, affinity: . upstream)
147
- originTextSelection. anchorPositionOffset = characterLocation. x
148
- let destinationTextSelection = textLayoutManager. destinationSelection (
149
- from: originTextSelection,
150
- in: direction. textSelectionNavigationDirection,
151
- offset: offset
152
- )
153
- return destinationTextSelection? . textRanges. first? . location. uiTextPosition
150
+
151
+ return destination? . textRanges. first? . location. uiTextPosition
154
152
}
155
153
156
154
/* Simple evaluation of positions */
0 commit comments