diff --git a/docs/guide/option.md b/docs/guide/option.md index e03b1c7..e200aa9 100644 --- a/docs/guide/option.md +++ b/docs/guide/option.md @@ -39,8 +39,8 @@ interface IEditorOption { resizerColor?: string; // 图片尺寸器颜色。默认:#4182D9 resizerSize?: number; // 图片尺寸器大小。默认:5 marginIndicatorSize?: number; // 页边距指示器长度。默认:35 - marginIndicatorColor?: string, // 页边距指示器颜色。默认:#BABABA - margins?: IMargin, // 页面边距。默认:[100, 120, 100, 120] + marginIndicatorColor?: string; // 页边距指示器颜色。默认:#BABABA + margins?: IMargin; // 页面边距。默认:[100, 120, 100, 120] pageMode?: PageMode; // 纸张模式:连页、分页。默认:分页 tdPadding?: number; // 单元格内边距。默认:5 defaultTrMinHeight?: number; // 默认表格行最小高度。默认:40 @@ -50,6 +50,7 @@ interface IEditorOption { pageNumber?: IPageNumber; // 页码信息。{bottom:number; size:number; font:string; color:string; rowFlex:RowFlex; format:string; numberType:NumberType;} paperDirection?: PaperDirection; // 纸张方向:纵向、横向 inactiveAlpha?: number; // 正文内容失焦时透明度。默认值:0.6 + historyMaxRecordCount: number; // 历史(撤销重做)最大记录次数。默认:100次 watermark?: IWatermark; // 水印信息。{data:string; color?:string; opacity?:number; size?:number; font?:string;} control?: IControlOption; // 控件信息。 {placeholderColor?:string; bracketColor?:string; prefix?:string; postfix?:string;} checkbox?: ICheckboxOption; // 复选框信息。{width?:number; height?:number; gap?:number; lineWidth?:number; fillStyle?:string; fontStyle?: string;} @@ -118,4 +119,4 @@ interface IPlaceholder { size?: number; // 字体大小。默认:16 font?: string; // 字体。默认:Yahei } -``` \ No newline at end of file +``` diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index 56d8e51..ce0d78d 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -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) diff --git a/src/editor/core/history/HistoryManager.ts b/src/editor/core/history/HistoryManager.ts index b7d661c..e8ef8f3 100644 --- a/src/editor/core/history/HistoryManager.ts +++ b/src/editor/core/history/HistoryManager.ts @@ -1,8 +1,15 @@ +import { Draw } from '../draw/Draw' + export class HistoryManager { - private readonly MAX_RECORD_COUNT = 1000 private undoStack: Array = [] private redoStack: Array = [] + 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() } } diff --git a/src/editor/index.ts b/src/editor/index.ts index 7c45d15..883a7ec 100644 --- a/src/editor/index.ts +++ b/src/editor/index.ts @@ -125,6 +125,7 @@ export default class Editor { defaultHyperlinkColor: '#0000FF', paperDirection: PaperDirection.VERTICAL, inactiveAlpha: 0.6, + historyMaxRecordCount: 100, ...options, header: headerOptions, footer: footerOptions, diff --git a/src/editor/interface/Editor.ts b/src/editor/interface/Editor.ts index 7cbac37..de2dc79 100644 --- a/src/editor/interface/Editor.ts +++ b/src/editor/interface/Editor.ts @@ -51,6 +51,7 @@ export interface IEditorOption { defaultHyperlinkColor?: string; paperDirection?: PaperDirection; inactiveAlpha?: number; + historyMaxRecordCount?: number; header?: IHeader; footer?: IFooter; pageNumber?: IPageNumber;