Hi Tomato,
You started quite well.
If you add the following line as your TextView's body first for debugging help:
let _ = Self._printChanges()
It will help you realize that when undoing, your textView's body is not recalculated. It means that nothing has changed for SwiftUI.
Of course, undoModel.point did change, but this property is not used to compute the view's body, so a change won't trigger a refresh.
To check further you could mirror undoModel.point into the position property, on which the TextView's body depends, eg by adding the following modifier :
.onChange(of:undoModel.point) { _, newValue in
position = newValue
}
and then undo works as expected.
This proposal only intends to point out what was missing. I assume that a complete fix would avoid copying from position to point and then back again to position, possibly by using a single property instead of 2.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: