Skip to content

Commit

Permalink
fix undo behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
fffpuzzle committed Jun 7, 2024
1 parent 2a95350 commit cc5c77b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/puzzle/Operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,15 @@ pzpr.classmgr.makeCommon({
push: function(ope) {
this[this.length++] = ope;
},
pop: function() {
if (this.length > 0) {
var ope = this[this.length - 1];
delete this[this.length - 1];
this.length--;
return ope;
}
return null;
},
some: function(func) {
return Array.prototype.slice.call(this).some(func);
}
Expand Down Expand Up @@ -716,8 +725,12 @@ pzpr.classmgr.makeCommon({
} else {
/* merged into previous operation, remove if noop */
if (this.lastope.isNoop && this.lastope.isNoop()) {
this.history.pop();
this.position--;
if (this.history[this.history.length - 1].length <= 1) {
this.history.pop();
this.position--;
} else {
this.history[this.history.length - 1].pop();
}
this.lastope = null;
}
}
Expand Down

0 comments on commit cc5c77b

Please sign in to comment.