feat: add history max record option #203
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +125,7 @@ export default class Editor {
|
||||
defaultHyperlinkColor: '#0000FF',
|
||||
paperDirection: PaperDirection.VERTICAL,
|
||||
inactiveAlpha: 0.6,
|
||||
historyMaxRecordCount: 100,
|
||||
...options,
|
||||
header: headerOptions,
|
||||
footer: footerOptions,
|
||||
|
||||
@@ -51,6 +51,7 @@ export interface IEditorOption {
|
||||
defaultHyperlinkColor?: string;
|
||||
paperDirection?: PaperDirection;
|
||||
inactiveAlpha?: number;
|
||||
historyMaxRecordCount?: number;
|
||||
header?: IHeader;
|
||||
footer?: IFooter;
|
||||
pageNumber?: IPageNumber;
|
||||
|
||||
Reference in New Issue
Block a user