Browse Source

Prune cellMap when clearing the undo stack.

ian-r-rose 8 years ago
parent
commit
f464647667
1 changed files with 10 additions and 0 deletions
  1. 10 0
      packages/notebook/src/celllist.ts

+ 10 - 0
packages/notebook/src/celllist.ts

@@ -511,6 +511,16 @@ class CellList implements IObservableUndoableVector<ICellModel> {
    * Clear the change stack.
    */
   clearUndo(): void {
+    //dispose of cells not in the current
+    //cell order.
+    for(let key of this._cellMap.keys()) {
+      if(ArrayExt.findFirstIndex(
+         toArray(this._cellOrder), id => (id.id)===key) === -1) {
+        let cell = this._cellMap.get(key) as ICellModel;
+        cell.dispose();
+        this._cellMap.delete(key);
+      }
+    }
     this._cellOrder.clearUndo();
   }