Skip to content

Commit 227cd4e

Browse files
authored
Fix CEUndoManager grouping (#69)
### Description Fixes #68 `DelegatedUndoManager` does not override ```swift func beginUndoGrouping() func endUndoGrouping() ``` so calling ```swift textView.undoManager?.beginUndoGrouping() ``` [here](https://github.com/CodeEditApp/CodeEditSourceEditor/blob/6b2c945501f0a5c15d8aa6d159fb2550c391bdd0/Sources/CodeEditSourceEditor/Controller/TextViewController%2BToggleComment.swift#L23) and [here](https://github.com/CodeEditApp/CodeEditSourceEditor/blob/6b2c945501f0a5c15d8aa6d159fb2550c391bdd0/Sources/CodeEditSourceEditor/Controller/TextViewController%2BIndentLines.swift#L25) does not undo as group as expected. I also updated the names to match between the `CEUndoManager` and `UndoManager`. ### Related Issues * #68 ### 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 #### Before: https://github.com/user-attachments/assets/f3d0de26-f359-464f-8fe1-15a7032fb3d7 #### After: https://github.com/user-attachments/assets/5716a972-cb2b-41ee-bee9-218967909eed
1 parent 1792167 commit 227cd4e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Sources/CodeEditTextView/Utils/CEUndoManager.swift

+12-4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public class CEUndoManager {
4040
parent?.redo()
4141
}
4242

43+
public override func beginUndoGrouping() {
44+
parent?.beginUndoGrouping()
45+
}
46+
47+
public override func endUndoGrouping() {
48+
parent?.endUndoGrouping()
49+
}
50+
4351
public override func registerUndo(withTarget target: Any, selector: Selector, object anObject: Any?) {
4452
// no-op, but just in case to save resources:
4553
removeAllActions()
@@ -164,18 +172,18 @@ public class CEUndoManager {
164172
// MARK: - Grouping
165173

166174
/// Groups all incoming mutations.
167-
public func beginGrouping() {
175+
public func beginUndoGrouping() {
168176
guard !isGrouping else {
169-
assertionFailure("UndoManager already in a group. Call `endGrouping` before this can be called.")
177+
assertionFailure("UndoManager already in a group. Call `beginUndoGrouping` before this can be called.")
170178
return
171179
}
172180
isGrouping = true
173181
}
174182

175183
/// Stops grouping all incoming mutations.
176-
public func endGrouping() {
184+
public func endUndoGrouping() {
177185
guard isGrouping else {
178-
assertionFailure("UndoManager not in a group. Call `beginGrouping` before this can be called.")
186+
assertionFailure("UndoManager not in a group. Call `endUndoGrouping` before this can be called.")
179187
return
180188
}
181189
isGrouping = false

0 commit comments

Comments
 (0)