Skip to content

Commit d65c2a4

Browse files
Skip Selection Update in Undo/Redo (#113)
### Description Skips updating the selection when performing undo/redo. ### Related Issues N/A ### Checklist - [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md) - [x] The issues this PR addresses are related to each other - [x] My changes generate no new warnings - [x] My code builds and runs on my machine - [x] My changes are all related to the related issue above - [x] I documented my code ### Screenshots N/A
1 parent 80fb884 commit d65c2a4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Sources/CodeEditTextView/Utils/CEUndoManager.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ public class CEUndoManager: UndoManager {
8080
NotificationCenter.default.post(name: .NSUndoManagerWillUndoChange, object: self)
8181
textView.textStorage.beginEditing()
8282
for mutation in item.mutations.reversed() {
83-
textView.replaceCharacters(in: mutation.inverse.range, with: mutation.inverse.string)
83+
textView.replaceCharacters(
84+
in: mutation.inverse.range,
85+
with: mutation.inverse.string,
86+
skipUpdateSelection: true
87+
)
8488
}
8589
textView.textStorage.endEditing()
8690

@@ -108,7 +112,11 @@ public class CEUndoManager: UndoManager {
108112
textView.selectionManager.removeCursors()
109113
textView.textStorage.beginEditing()
110114
for mutation in item.mutations {
111-
textView.replaceCharacters(in: mutation.mutation.range, with: mutation.mutation.string)
115+
textView.replaceCharacters(
116+
in: mutation.mutation.range,
117+
with: mutation.mutation.string,
118+
skipUpdateSelection: true
119+
)
112120
}
113121
textView.textStorage.endEditing()
114122

0 commit comments

Comments
 (0)