From 0f446b7739197ad9a0f2408a55630b5c182c1b4e Mon Sep 17 00:00:00 2001 From: Khan Winter <35942988+thecoolwinter@users.noreply.github.com> Date: Thu, 26 Jun 2025 13:42:27 -0500 Subject: [PATCH] Skip Selection Update in Undo/Redo --- Sources/CodeEditTextView/Utils/CEUndoManager.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Sources/CodeEditTextView/Utils/CEUndoManager.swift b/Sources/CodeEditTextView/Utils/CEUndoManager.swift index 722b188ed..2af68d9e0 100644 --- a/Sources/CodeEditTextView/Utils/CEUndoManager.swift +++ b/Sources/CodeEditTextView/Utils/CEUndoManager.swift @@ -80,7 +80,11 @@ public class CEUndoManager: UndoManager { NotificationCenter.default.post(name: .NSUndoManagerWillUndoChange, object: self) textView.textStorage.beginEditing() for mutation in item.mutations.reversed() { - textView.replaceCharacters(in: mutation.inverse.range, with: mutation.inverse.string) + textView.replaceCharacters( + in: mutation.inverse.range, + with: mutation.inverse.string, + skipUpdateSelection: true + ) } textView.textStorage.endEditing() @@ -108,7 +112,11 @@ public class CEUndoManager: UndoManager { textView.selectionManager.removeCursors() textView.textStorage.beginEditing() for mutation in item.mutations { - textView.replaceCharacters(in: mutation.mutation.range, with: mutation.mutation.string) + textView.replaceCharacters( + in: mutation.mutation.range, + with: mutation.mutation.string, + skipUpdateSelection: true + ) } textView.textStorage.endEditing()