feat: add history max record option #203

pr675
Hufe921 3 years ago
parent 7628eee283
commit c46750557a

@ -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
}
```
```

@ -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;

Loading…
Cancel
Save