history-manager-base.js 874 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. class HistoryManagerBase {
  2. // 步骤控制
  3. undoArray = [];
  4. redoArray = [];
  5. constructor() {}
  6. push(command) {
  7. this.undoArray.unshift(command);
  8. this.redoArray.length = 0;
  9. // 步骤数最大 100
  10. if (this.undoArray.length > 100) {
  11. this.undoArray.length = 100;
  12. }
  13. }
  14. async undo() {
  15. const command = this.undoArray.shift();
  16. if (command) {
  17. await command.undo();
  18. this.redoArray.unshift(command);
  19. }
  20. }
  21. async redo() {
  22. const command = this.redoArray.shift();
  23. if (command) {
  24. await command.redo();
  25. this.undoArray.unshift(command);
  26. }
  27. }
  28. rebase() {
  29. this.undoArray.length = 0;
  30. this.redoArray.length = 0;
  31. }
  32. reset() {}
  33. snapshot() {}
  34. }
  35. module.exports = HistoryManagerBase;