changeset 467:b963af7e6eaf

Clear undo history ahead of read pointer when updating the history.
author Lucas Thompson <dev@lucas.im>
date Fri, 30 Jun 2017 15:27:56 +0100
parents 8820a133bcf5
children 2fb2357420f9
files src/app/Session.ts
diffstat 1 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/app/Session.ts	Fri Jun 30 14:50:00 2017 +0100
+++ b/src/app/Session.ts	Fri Jun 30 15:27:56 2017 +0100
@@ -80,7 +80,7 @@
 
   shift(): T {
     const item = this.shiftMutating();
-    this.history.push([...this.stack]);
+    this.updateHistory();
     return item;
   }
 
@@ -91,7 +91,7 @@
 
   unshift(item: T): number {
     const newLength = this.unshift(item);
-    this.history.push([...this.stack]);
+    this.updateHistory();
     return newLength;
   }
 
@@ -111,7 +111,7 @@
 
   set(index: number, value: T) {
     this.setMutating(index, value);
-    this.history.push([...this.stack]);
+    this.updateHistory();
   }
 
   setMutating(index: number, value: T) {
@@ -141,7 +141,7 @@
       }
       return acc;
     }, [] as T[]);
-    this.history.push([...this.stack]);
+    this.updateHistory();
   }
 
   stepBack(): void {
@@ -162,6 +162,17 @@
     }
   }
 
+  updateHistory(): void {
+    if (this.historyOffset !== 0) {
+      this.history = this.history.slice(
+        0,
+        this.history.length - this.historyOffset
+      );
+      this.historyOffset = 0;
+    }
+    this.history.push([...this.stack]);
+  }
+
   toIterable(): Iterable<T> {
     return this.stack;
   }