UndoTo returns the action, action data, and state at the given index and decrements the index to the previous record. If idx is out of range then returns empty everything
(idx int)
| 231 | // and decrements the index to the previous record. |
| 232 | // If idx is out of range then returns empty everything |
| 233 | func (us *Stack) UndoTo(idx int) (action, data string, state []string) { |
| 234 | us.Mu.Lock() |
| 235 | if idx < 0 || idx >= len(us.Records) { |
| 236 | us.Mu.Unlock() |
| 237 | return |
| 238 | } |
| 239 | rec := us.Records[idx] |
| 240 | action = rec.Action |
| 241 | data = rec.Data |
| 242 | state = us.RecState(idx) |
| 243 | us.Index = idx - 1 |
| 244 | us.Mu.Unlock() |
| 245 | return |
| 246 | } |
| 247 | |
| 248 | // Redo returns the action, data at the *next* index, and the state at the |
| 249 | // index *after that*. |