- Feb 8, 2004
- 12,604
- 15
- 81
There must be a better way than having a method that's the reverse operation of every other method
How are they implemented in things like libreoffice etc?
Most undos I've implemented have been stack based. Basically you take a base state and reapply all the changes minus the ones you remove.
So with storing states, the object that represents the current page of a word document would be copied and stored in some collection before every state changing action the user takes. Subsequent actions that cause change also cause each version of the object to be stored in the same collection.
Man that's beautiful.
Similar to the way a version control system works, but I think the command pattern is more common because it's a lot more efficient, especially for data that is not intended to be durable.
So with storing states, the object that represents the current page of a word document would be copied and stored in some collection before every state changing action the user takes. Subsequent actions that cause change also cause each version of the object to be stored in the same collection.
Man that's beautiful.