Skip to content

Commit

Permalink
fix: history undo&redo (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
mizy committed Oct 13, 2022
1 parent 7924e6e commit f67b7ab
Show file tree
Hide file tree
Showing 66 changed files with 715 additions and 632 deletions.
2 changes: 1 addition & 1 deletion demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Editor extends PureComponent {
await this.editor.schema.setInitData(testdata);
await this.editor.schema.format();
await this.editor.controller.autoFit();

this.editor.schema.history.reset();
this.addEditorEvent();
window.mm = this.editor;
// for (let i = 0;i < 1000;i++) {
Expand Down
31 changes: 27 additions & 4 deletions dist/VEditor.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17765,18 +17765,33 @@ var History = /** @class */ (function () {
};
// 重做
History.prototype.redo = function () {
if (this.index >= this.schemaList.length - 1) {
return false;
}
this.schema.data = JSON.parse(this.schemaList[++this.index]);
this.schema.editor.fire("change");
return true;
};
// 撤销
History.prototype.undo = function () {
if (this.index < 1) {
return false;
}
this.schema.data = JSON.parse(this.schemaList[--this.index]);
this.schema.editor.fire("change");
return true;
};
History.prototype.clear = function () {
this.schemaList = [];
this.index = -1;
};
History.prototype.reset = function () {
if (this.schemaList.length <= 0) {
return;
}
this.index = 0;
this.schemaList = [this.schemaList[0]];
};
return History;
}());
/* harmony default export */ const Model_History = (History);
Expand Down Expand Up @@ -17889,11 +17904,17 @@ var Schema = /** @class */ (function () {
"line:remove",
"delete",
];
var editorEvents = ["autofit"];
historyChangeEvents.forEach(function (event) {
_this.editor.graph.on(event, function () {
_this.history.push(_this.makeNowDataMap());
}, 9999);
});
editorEvents.forEach(function (event) {
_this.editor.on(event, function () {
_this.history.push(_this.makeNowDataMap());
}, 9999);
});
};
/**
* 历史入栈最新数据
Expand Down Expand Up @@ -18000,13 +18021,14 @@ var Schema = /** @class */ (function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.history.redo()) return [3 /*break*/, 2];
this.editor.graph.clearGraph();
this.history.redo();
return [4 /*yield*/, this.renderData()];
case 1:
_a.sent();
this.editor.fire("redo");
return [2 /*return*/];
_a.label = 2;
case 2: return [2 /*return*/];
}
});
});
Expand All @@ -18019,13 +18041,14 @@ var Schema = /** @class */ (function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.history.undo()) return [3 /*break*/, 2];
this.editor.graph.clearGraph();
this.history.undo();
return [4 /*yield*/, this.renderData()];
case 1:
_a.sent();
this.editor.fire("undo");
return [2 /*return*/];
_a.label = 2;
case 2: return [2 /*return*/];
}
});
});
Expand Down
31 changes: 27 additions & 4 deletions dist/VEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4146,18 +4146,33 @@ var History = /** @class */ (function () {
};
// 重做
History.prototype.redo = function () {
if (this.index >= this.schemaList.length - 1) {
return false;
}
this.schema.data = JSON.parse(this.schemaList[++this.index]);
this.schema.editor.fire("change");
return true;
};
// 撤销
History.prototype.undo = function () {
if (this.index < 1) {
return false;
}
this.schema.data = JSON.parse(this.schemaList[--this.index]);
this.schema.editor.fire("change");
return true;
};
History.prototype.clear = function () {
this.schemaList = [];
this.index = -1;
};
History.prototype.reset = function () {
if (this.schemaList.length <= 0) {
return;
}
this.index = 0;
this.schemaList = [this.schemaList[0]];
};
return History;
}());
/* harmony default export */ const Model_History = (History);
Expand Down Expand Up @@ -4270,11 +4285,17 @@ var Schema = /** @class */ (function () {
"line:remove",
"delete",
];
var editorEvents = ["autofit"];
historyChangeEvents.forEach(function (event) {
_this.editor.graph.on(event, function () {
_this.history.push(_this.makeNowDataMap());
}, 9999);
});
editorEvents.forEach(function (event) {
_this.editor.on(event, function () {
_this.history.push(_this.makeNowDataMap());
}, 9999);
});
};
/**
* 历史入栈最新数据
Expand Down Expand Up @@ -4381,13 +4402,14 @@ var Schema = /** @class */ (function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.history.redo()) return [3 /*break*/, 2];
this.editor.graph.clearGraph();
this.history.redo();
return [4 /*yield*/, this.renderData()];
case 1:
_a.sent();
this.editor.fire("redo");
return [2 /*return*/];
_a.label = 2;
case 2: return [2 /*return*/];
}
});
});
Expand All @@ -4400,13 +4422,14 @@ var Schema = /** @class */ (function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.history.undo()) return [3 /*break*/, 2];
this.editor.graph.clearGraph();
this.history.undo();
return [4 /*yield*/, this.renderData()];
case 1:
_a.sent();
this.editor.fire("undo");
return [2 /*return*/];
_a.label = 2;
case 2: return [2 /*return*/];
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/assets/search.js

Large diffs are not rendered by default.

Loading

0 comments on commit f67b7ab

Please sign in to comment.