feat:rich text editor by canvas

This commit is contained in:
黄云飞
2021-11-12 22:22:05 +08:00
commit 2739d4069f
36 changed files with 1251 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
export class HistoryManager {
private readonly MAX_RECORD_COUNT = 1000
private undoStack: Array<Function> = []
private redoStack: Array<Function> = []
undo() {
if (this.undoStack.length > 1) {
const pop = this.undoStack.pop()!
this.redoStack.push(pop)
if (this.undoStack.length) {
this.undoStack[this.undoStack.length - 1]()
}
}
}
redo() {
if (this.redoStack.length) {
const pop = this.redoStack.pop()!
this.undoStack.push(pop)
pop()
}
}
execute(fn: Function) {
this.undoStack.push(fn)
if (this.redoStack.length) {
this.redoStack = []
}
while (this.undoStack.length > this.MAX_RECORD_COUNT) {
this.undoStack.shift()
}
}
}