feat: record the first cursor position #517

This commit is contained in:
Hufe921
2024-04-19 21:31:53 +08:00
parent cdbd1ff4de
commit 0878506062
3 changed files with 16 additions and 5 deletions
+11 -5
View File
@@ -246,7 +246,8 @@ export class Draw {
this.render({
isInit: true,
isSetCursor: false
isSetCursor: false,
isFirstRender: true
})
}
@@ -1013,7 +1014,8 @@ export class Draw {
// 渲染&计算&清空历史记录
this.historyManager.recovery()
this.render({
isSetCursor: false
isSetCursor: false,
isFirstRender: true
})
}
@@ -2148,7 +2150,8 @@ export class Draw {
isCompute = true,
isLazy = true,
isInit = false,
isSourceHistory = false
isSourceHistory = false,
isFirstRender = false
} = payload || {}
let { curIndex } = payload || {}
const innerWidth = this.getInnerWidth()
@@ -2232,8 +2235,11 @@ export class Draw {
}
this.cursor.drawCursor()
}
// 历史记录用于undo、redo
if (isSubmitHistory) {
// 历史记录用于undo、redo(非首次渲染内容变更 || 第一次存在光标时)
if (
(isSubmitHistory && !isFirstRender) ||
(curIndex !== undefined && this.historyManager.isStackEmpty())
) {
const oldElementList = getSlimCloneElementList(this.elementList)
const oldHeaderElementList = getSlimCloneElementList(
this.header.getElementList()
@@ -46,6 +46,10 @@ export class HistoryManager {
return !!this.redoStack.length
}
public isStackEmpty(): boolean {
return !this.undoStack.length && !this.redoStack.length
}
public recovery() {
this.undoStack = []
this.redoStack = []
+1
View File
@@ -11,6 +11,7 @@ export interface IDrawOption {
isLazy?: boolean
isInit?: boolean
isSourceHistory?: boolean
isFirstRender?: boolean
}
export interface IForceUpdateOption {