Skip to content

Commit

Permalink
Merge pull request #63 from ArunBohra12/master
Browse files Browse the repository at this point in the history
πŸ›  Fix the error when undo and redo
  • Loading branch information
theabbie authored Feb 27, 2023
2 parents b55796a + 2d0f262 commit 2aa8263
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,25 @@ class Canvas {

undo() {
this.clear();
this.redo_arr.push(this.steps.pop());
const lastRemovedItem = this.steps.pop();

if (!lastRemovedItem) return;

this.redo_arr.push(lastRemovedItem);
var step;
this.steps.forEach((step) => {
this.setcolor(step[2]);
this.ctx.globalAlpha = step[3];
this.draw(step[0], step[1], true);
});
}

redo() {
this.steps.push(this.redo_arr.pop());
const lastRemovedItem = this.redo_arr.pop();

if (!lastRemovedItem) return;

this.steps.push(lastRemovedItem);
var step;
this.steps.forEach((step) => {
this.setcolor(step[2]);
Expand Down

0 comments on commit 2aa8263

Please sign in to comment.