feat: record the first cursor position #517

pr675
Hufe921 2 years ago
parent cdbd1ff4de
commit 0878506062

@ -246,7 +246,8 @@ export class Draw {
this.render({ this.render({
isInit: true, isInit: true,
isSetCursor: false isSetCursor: false,
isFirstRender: true
}) })
} }
@ -1013,7 +1014,8 @@ export class Draw {
// 渲染&计算&清空历史记录 // 渲染&计算&清空历史记录
this.historyManager.recovery() this.historyManager.recovery()
this.render({ this.render({
isSetCursor: false isSetCursor: false,
isFirstRender: true
}) })
} }
@ -2148,7 +2150,8 @@ export class Draw {
isCompute = true, isCompute = true,
isLazy = true, isLazy = true,
isInit = false, isInit = false,
isSourceHistory = false isSourceHistory = false,
isFirstRender = false
} = payload || {} } = payload || {}
let { curIndex } = payload || {} let { curIndex } = payload || {}
const innerWidth = this.getInnerWidth() const innerWidth = this.getInnerWidth()
@ -2232,8 +2235,11 @@ export class Draw {
} }
this.cursor.drawCursor() this.cursor.drawCursor()
} }
// 历史记录用于undo、redo // 历史记录用于undo、redo非首次渲染内容变更 || 第一次存在光标时)
if (isSubmitHistory) { if (
(isSubmitHistory && !isFirstRender) ||
(curIndex !== undefined && this.historyManager.isStackEmpty())
) {
const oldElementList = getSlimCloneElementList(this.elementList) const oldElementList = getSlimCloneElementList(this.elementList)
const oldHeaderElementList = getSlimCloneElementList( const oldHeaderElementList = getSlimCloneElementList(
this.header.getElementList() this.header.getElementList()

@ -46,6 +46,10 @@ export class HistoryManager {
return !!this.redoStack.length return !!this.redoStack.length
} }
public isStackEmpty(): boolean {
return !this.undoStack.length && !this.redoStack.length
}
public recovery() { public recovery() {
this.undoStack = [] this.undoStack = []
this.redoStack = [] this.redoStack = []

@ -11,6 +11,7 @@ export interface IDrawOption {
isLazy?: boolean isLazy?: boolean
isInit?: boolean isInit?: boolean
isSourceHistory?: boolean isSourceHistory?: boolean
isFirstRender?: boolean
} }
export interface IForceUpdateOption { export interface IForceUpdateOption {

Loading…
Cancel
Save