Undo returns the action, action data, and state at the current index and decrements the index to the previous record. This state is the state just prior to the action. If already at the start (Index = -1) then returns empty everything Before calling, first check MustSaveUndoStart() -- if false, then
()
| 213 | // Before calling, first check MustSaveUndoStart() -- if false, then you need |
| 214 | // to call SaveUndoStart() so that the state just before Undoing can be redone! |
| 215 | func (us *Stack) Undo() (action, data string, state []string) { |
| 216 | us.Mu.Lock() |
| 217 | if us.Index < 0 || us.Index >= len(us.Records) { |
| 218 | us.Mu.Unlock() |
| 219 | return |
| 220 | } |
| 221 | rec := us.Records[us.Index] |
| 222 | action = rec.Action |
| 223 | data = rec.Data |
| 224 | state = us.RecState(us.Index) |
| 225 | us.Index-- |
| 226 | us.Mu.Unlock() |
| 227 | return |
| 228 | } |
| 229 | |
| 230 | // UndoTo returns the action, action data, and state at the given index |
| 231 | // and decrements the index to the previous record. |