File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Sources/CodeEditTextView/Utils Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -122,10 +122,14 @@ public class CEUndoManager: UndoManager {
122122 /// should be one continuous range. This merges those ranges into a set of disjoint ranges before updating the
123123 /// selection manager.
124124 private func updateSelectionsForMutations( mutations: [ TextMutation ] ) {
125- if mutations. reduce ( 0 , { $0 + $1. range. length } ) == 0 , let last = mutations. last {
126- // If the mutations are only deleting text (no replacement), we just place the cursor at the last range,
127- // since all the ranges are the same but the other method will return no ranges (empty range).
128- textView? . selectionManager. setSelectedRange ( last. range)
125+ if mutations. reduce ( 0 , { $0 + $1. range. length } ) == 0 {
126+ if let minimumMutation = mutations. min ( by: { $0. range. location < $1. range. location } ) {
127+ // If the mutations are only deleting text (no replacement), we just place the cursor at the last range,
128+ // since all the ranges are the same but the other method will return no ranges (empty range).
129+ textView? . selectionManager. setSelectedRange (
130+ NSRange ( location: minimumMutation. range. location, length: 0 )
131+ )
132+ }
129133 } else {
130134 let mergedRanges = mutations. reduce ( into: IndexSet ( ) , { set, mutation in
131135 set. insert ( range: mutation. range)
You can’t perform that action at this time.
0 commit comments