Skip to content

我在实现undo和redo功能的时候遇到了一些问题 #3692

@BlInYo

Description

@BlInYo

我使用change_cell_value事件想要实现一个简单的redo和undo功能,单元格的值发生改变的时候将它放到history类中的一个stack中。问题在于我在撤销和重做的时候使用了changeCellValue()方法,而这个方法也会触发change_cell_value事件,导致每次撤销的时候都会触发history.push会往undoStack里push一个记录。请问是否有其他的事件能够区分是用户手动修改还是因为changeCellValue而导致的单元格内容变化。
还是说只是我实现思路有问题😭
ps:this就是ListTable的实例

this.addEventListener("change_cell_value", (cell) => {
      const { row, col, changedValue, currentValue } = cell || {};
      this.history.push(
        {
          row,
          col,
          value: changedValue,
        },
        {
          row,
          col,
          value: currentValue,
        }
      );
    });
this.history = new History((cell) => {
      const { row, col, value } = cell || {};
      this.changeCellValue(col, row, value);
    });

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions