Honour reductions to MAX_UNDO (#2078)

* Honour reductions to MAX_UNDO

If MAX_UNDO is reduced, we now throw away the extra records in the stack, as opposed to just not growing it anymore.

* shift != unshift

Apparently I need a new brain.

* Ensure MAX_UNDO isn’t negative.
This commit is contained in:
Neil Fraser
2018-10-12 06:34:23 -07:00
committed by RoboErikG
parent 1b9b613ca5
commit 7531b323b2

View File

@@ -523,8 +523,8 @@ Blockly.Workspace.prototype.fireChangeListener = function(event) {
if (event.recordUndo) {
this.undoStack_.push(event);
this.redoStack_.length = 0;
if (this.undoStack_.length > this.MAX_UNDO) {
this.undoStack_.unshift();
while (this.undoStack_.length > this.MAX_UNDO && this.MAX_UNDO >= 0) {
this.undoStack_.shift();
}
}
for (var i = 0, func; func = this.listeners_[i]; i++) {