Skip to content

Commit

Permalink
Fix undo/redo action, call drawing:changed event when the state updat…
Browse files Browse the repository at this point in the history
…e is finished

[#184171460]
[#184171389]
  • Loading branch information
pjanik committed Jan 26, 2023
1 parent 9617602 commit ae2dba4
Show file tree
Hide file tree
Showing 5 changed files with 9,616 additions and 58 deletions.
10 changes: 6 additions & 4 deletions app/scripts/drawing-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,17 @@ DrawingTool.prototype.pushToHistory = function () {
};

DrawingTool.prototype.undo = function () {
this._history.undo();
this._history.undo(() => {
this._fireDrawingChanged();
});
this._fireHistoryEvents();
this._fireDrawingChanged();
};

DrawingTool.prototype.redo = function () {
this._history.redo();
this._history.redo(() => {
this._fireDrawingChanged();
});
this._fireHistoryEvents();
this._fireDrawingChanged();
};

DrawingTool.prototype.resetHistory = function () {
Expand Down
13 changes: 7 additions & 6 deletions app/scripts/undo-redo.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ function UndoRedo(drawTool) {
}.bind(this));
}

UndoRedo.prototype.undo = function () {
UndoRedo.prototype.undo = function (callback) {
var prevState = this._storage[this._idx - 1];
if (!prevState) {
return;
}
this._load(prevState);
this._load(prevState, callback);
this._idx -= 1;
};

UndoRedo.prototype.redo = function () {
UndoRedo.prototype.redo = function (callback) {
var nextState = this._storage[this._idx + 1];
if (!nextState) {
return;
}
this._load(nextState);
this._load(nextState, callback);
this._idx += 1;
};

Expand Down Expand Up @@ -64,10 +64,11 @@ UndoRedo.prototype._lastState = function () {
return this._storage[this._idx];
};

UndoRedo.prototype._load = function (state) {
UndoRedo.prototype._load = function (state, callback = null) {
// Note that #load is a normal action that updates history. However when
// a state is restored from the history, it's definitely unwanted.
this.dt.load(state, null, true);
const noHistoryUpdate = true;
this.dt.load(state, callback, noHistoryUpdate);
};

UndoRedo.prototype._cutOffOldStates = function () {
Expand Down
4 changes: 2 additions & 2 deletions dist/drawing-tool.js

Large diffs are not rendered by default.

Loading

0 comments on commit ae2dba4

Please sign in to comment.