Skip to content

Commit

Permalink
Fix CEUndoManager grouping (#69)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
hi2gage authored Feb 11, 2025
1 parent 1792167 commit 227cd4e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Sources/CodeEditTextView/Utils/CEUndoManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ public class CEUndoManager {
parent?.redo()
}

public override func beginUndoGrouping() {
parent?.beginUndoGrouping()
}

public override func endUndoGrouping() {
parent?.endUndoGrouping()
}

public override func registerUndo(withTarget target: Any, selector: Selector, object anObject: Any?) {
// no-op, but just in case to save resources:
removeAllActions()
Expand Down Expand Up @@ -164,18 +172,18 @@ public class CEUndoManager {
// MARK: - Grouping

/// Groups all incoming mutations.
public func beginGrouping() {
public func beginUndoGrouping() {
guard !isGrouping else {
assertionFailure("UndoManager already in a group. Call `endGrouping` before this can be called.")
assertionFailure("UndoManager already in a group. Call `beginUndoGrouping` before this can be called.")
return
}
isGrouping = true
}

/// Stops grouping all incoming mutations.
public func endGrouping() {
public func endUndoGrouping() {
guard isGrouping else {
assertionFailure("UndoManager not in a group. Call `beginGrouping` before this can be called.")
assertionFailure("UndoManager not in a group. Call `endUndoGrouping` before this can be called.")
return
}
isGrouping = false
Expand Down

0 comments on commit 227cd4e

Please sign in to comment.