| 1479 | } |
| 1480 | |
| 1481 | addToHistory(change:Change|SpanChange) { |
| 1482 | let history = this.history; |
| 1483 | // Bail if we're currently doing an undo or redo |
| 1484 | if(history.transitioning) return; |
| 1485 | |
| 1486 | // Truncate the history tree to ancestors of the current state. |
| 1487 | // @NOTE: In a fancier implementation we could maintain branching history instead. |
| 1488 | if(history.items.length > history.position) { |
| 1489 | history.items.length = history.position; |
| 1490 | } |
| 1491 | let changeSet:HistoryItem; |
| 1492 | // If the last history step hasn't been finalized, we want to keep glomming onto it. |
| 1493 | let last = history.items[history.items.length - 1]; |
| 1494 | if(last && !last.finalized) changeSet = last; |
| 1495 | else changeSet = {changes: []}; |
| 1496 | |
| 1497 | // @FIXME: Is this check still necessary with history.transitioning? |
| 1498 | if(change.origin !== "+mdundo" && change.origin !== "+mdredo") { |
| 1499 | changeSet.changes.push(change); |
| 1500 | } |
| 1501 | // Finally add the history step to the history stack (if it's not already in there). |
| 1502 | if(changeSet !== last) { |
| 1503 | history.position++; |
| 1504 | history.items.push(changeSet); |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | finalizeLastHistoryEntry() { |
| 1509 | let history = this.history; |