Skip to content

Commit

Permalink
1.5.0 undo/redo bug fix. toggle (on/off)
Browse files Browse the repository at this point in the history
  • Loading branch information
alimozdemir committed May 13, 2020
1 parent 877ba2e commit 161e87a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
14 changes: 9 additions & 5 deletions demo/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.4.0/fabric.min.js"></script>
<script src="libs/jsonviewer.js"></script>
<script src="../src/index.min.js"></script>
<script src="../src/index.js"></script>
<script>
let isDrawingMode = false;
const canvas = new fabric.Canvas(document.querySelector('canvas'));
Expand Down Expand Up @@ -103,11 +103,15 @@

// remove objects
if (activeObjects.length > 0) {
activeObjects.forEach((object) => {
if (!object.isEditing) {
canvas.remove(object);
canvas.offHistory();

for (var i = 0; i < activeObjects.length; i++) {
if (!activeObjects[i].isEditing) {
canvas.remove(activeObjects[i]);
}
});
}

canvas.onHistory();
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fabric-history",
"version": "1.4.0",
"version": "1.5.0",
"description": "Undo and redo implementations on fabric.js",
"main": "src/index.min.js",
"scripts": {
Expand Down
22 changes: 19 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fabric.Canvas.prototype.undo = function (callback) {
if (history) {
// Push the current state to the redo history
this.historyRedo.push(this._historyNext());

this.historyNextState = history;
this._loadHistory(history, 'history:undo', callback);
} else {
this.historyProcessing = false;
Expand All @@ -107,7 +107,7 @@ fabric.Canvas.prototype.redo = function (callback) {
if (history) {
// Every redo action is actually a new action to the undo history
this.historyUndo.push(this._historyNext());

this.historyNextState = history;
this._loadHistory(history, 'history:redo', callback);
} else {
this.historyProcessing = false;
Expand All @@ -134,4 +134,20 @@ fabric.Canvas.prototype.clearHistory = function() {
this.historyUndo = [];
this.historyRedo = [];
this.fire('history:clear');
}
}

/**
* Off the history
*/
fabric.Canvas.prototype.offHistory = function() {
this.historyProcessing = true;
}

/**
* On the history
*/
fabric.Canvas.prototype.onHistory = function() {
this.historyProcessing = false;

this._historySaveAction();
}
2 changes: 1 addition & 1 deletion src/index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 161e87a

Please sign in to comment.