Skip to content

Commit 28baa1e

Browse files
committed
Revert "Preserves position in line fragments when moving up and down (#57)"
This reverts commit bb5e95e.
1 parent 65931d3 commit 28baa1e

File tree

2 files changed

+13
-48
lines changed

2 files changed

+13
-48
lines changed

Sources/STTextViewUIKit/Extensions/NSTextLayoutManager+Helpers.swift

-33
This file was deleted.

Sources/STTextViewUIKit/STTextView+UITextInput.swift

+13-15
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,20 @@ extension STTextView: UITextInput {
135135
guard let position = position as? STTextLocation else {
136136
return nil
137137
}
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+
)
143149
}
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
154152
}
155153

156154
/* Simple evaluation of positions */

0 commit comments

Comments
 (0)