From 087850606224290bc6e1992711416ac0acbfa45b Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Fri, 19 Apr 2024 21:31:53 +0800 Subject: [PATCH] feat: record the first cursor position #517 --- src/editor/core/draw/Draw.ts | 16 +++++++++++----- src/editor/core/history/HistoryManager.ts | 4 ++++ src/editor/interface/Draw.ts | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index 2a007bd..93eabf1 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -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() diff --git a/src/editor/core/history/HistoryManager.ts b/src/editor/core/history/HistoryManager.ts index 402af8c..2e2518f 100644 --- a/src/editor/core/history/HistoryManager.ts +++ b/src/editor/core/history/HistoryManager.ts @@ -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 = [] diff --git a/src/editor/interface/Draw.ts b/src/editor/interface/Draw.ts index 5d46057..7cc97a6 100644 --- a/src/editor/interface/Draw.ts +++ b/src/editor/interface/Draw.ts @@ -11,6 +11,7 @@ export interface IDrawOption { isLazy?: boolean isInit?: boolean isSourceHistory?: boolean + isFirstRender?: boolean } export interface IForceUpdateOption {