Skip to content

Commit

Permalink
feat:x6-plugin-history,撤销回退插件原理
Browse files Browse the repository at this point in the history
  • Loading branch information
yelikang committed Aug 19, 2024
1 parent df812a7 commit 494716f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/x6-plugin-history/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export class History
this.model.on('batch:start', this.initBatchCommand, this)
this.model.on('batch:stop', this.storeBatchCommand, this)
if (this.options.eventNames) {
// 监听哪些事件操作需要进入撤销回退队列,统一进入addCommand中处理
this.options.eventNames.forEach((name, index) => {
this.handlers[index] = this.addCommand.bind(this, name)
this.model.on(name, this.handlers[index])
Expand Down Expand Up @@ -525,11 +526,13 @@ export class History
}

protected push(cmd: History.Command, options: KeyValue) {
// 有新的操作进入撤销队列undoStack时,重做队列redoStack清空
this.redoStack = []
if (cmd.batch) {
this.lastBatchIndex = Math.max(this.lastBatchIndex, 0)
this.emit('batch', { cmd, options })
} else {
// 操作进入撤销队列
this.undoStackPush(cmd)
this.consolidateCommands()
this.notify('add', cmd, options)
Expand Down

0 comments on commit 494716f

Please sign in to comment.