Skip to content

Commit

Permalink
feat: record the first cursor position #517
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Apr 19, 2024
1 parent cdbd1ff commit 0878506
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/editor/core/draw/Draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ export class Draw {

this.render({
isInit: true,
isSetCursor: false
isSetCursor: false,
isFirstRender: true
})
}

Expand Down Expand Up @@ -1013,7 +1014,8 @@ export class Draw {
// 渲染&计算&清空历史记录
this.historyManager.recovery()
this.render({
isSetCursor: false
isSetCursor: false,
isFirstRender: true
})
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions src/editor/core/history/HistoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
1 change: 1 addition & 0 deletions src/editor/interface/Draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface IDrawOption {
isLazy?: boolean
isInit?: boolean
isSourceHistory?: boolean
isFirstRender?: boolean
}

export interface IForceUpdateOption {
Expand Down

0 comments on commit 0878506

Please sign in to comment.