feat: add history max record option #203

This commit is contained in:
Hufe921
2023-06-16 21:42:55 +08:00
parent 7628eee283
commit c46750557a
5 changed files with 16 additions and 6 deletions
+1 -1
View File
@@ -140,7 +140,7 @@ export class Draw {
this._createPage(0)
this.i18n = new I18n()
this.historyManager = new HistoryManager()
this.historyManager = new HistoryManager(this)
this.position = new Position(this)
this.zone = new Zone(this)
this.range = new RangeManager(this)
+9 -2
View File
@@ -1,8 +1,15 @@
import { Draw } from '../draw/Draw'
export class HistoryManager {
private readonly MAX_RECORD_COUNT = 1000
private undoStack: Array<Function> = []
private redoStack: Array<Function> = []
private maxRecordCount: number
constructor(draw: Draw) {
// 忽略第一次历史记录
this.maxRecordCount = draw.getOptions().historyMaxRecordCount + 1
}
public undo() {
if (this.undoStack.length > 1) {
@@ -27,7 +34,7 @@ export class HistoryManager {
if (this.redoStack.length) {
this.redoStack = []
}
while (this.undoStack.length > this.MAX_RECORD_COUNT) {
while (this.undoStack.length > this.maxRecordCount) {
this.undoStack.shift()
}
}
+1
View File
@@ -125,6 +125,7 @@ export default class Editor {
defaultHyperlinkColor: '#0000FF',
paperDirection: PaperDirection.VERTICAL,
inactiveAlpha: 0.6,
historyMaxRecordCount: 100,
...options,
header: headerOptions,
footer: footerOptions,
+1
View File
@@ -51,6 +51,7 @@ export interface IEditorOption {
defaultHyperlinkColor?: string;
paperDirection?: PaperDirection;
inactiveAlpha?: number;
historyMaxRecordCount?: number;
header?: IHeader;
footer?: IFooter;
pageNumber?: IPageNumber;