# HG changeset patch # User Lucas Thompson # Date 1498832876 -3600 # Node ID b963af7e6eafc50d8ef6ba328ced274952686616 # Parent 8820a133bcf543a4ae2ca94d12a957923f7b436f Clear undo history ahead of read pointer when updating the history. diff -r 8820a133bcf5 -r b963af7e6eaf src/app/Session.ts --- 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 { return this.stack; }