From 1b25afb664b6feff8a0e96dda53a0a3b252663c7 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Fri, 28 Jul 2023 19:22:01 +0800 Subject: [PATCH] fix: contentChange call error during initialization #224 --- src/editor/core/draw/Draw.ts | 10 +++++++--- src/editor/interface/Draw.ts | 1 + src/main.ts | 6 ++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index d97da99..6189cad 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -222,7 +222,10 @@ export class Draw { this.intersectionPageNo = 0 this.lazyRenderIntersectionObserver = null - this.render({ isSetCursor: false }) + this.render({ + isInit: true, + isSetCursor: false + }) } public getMode(): EditorMode { @@ -1708,7 +1711,8 @@ export class Draw { isSubmitHistory = true, isSetCursor = true, isCompute = true, - isLazy = true + isLazy = true, + isInit = false } = payload || {} let { curIndex } = payload || {} const innerWidth = this.getInnerWidth() @@ -1823,7 +1827,7 @@ export class Draw { this.eventBus.emit('pageSizeChange', this.pageRowList.length) } // 文档内容改变 - if (isSubmitHistory) { + if (isSubmitHistory && !isInit) { if (this.listener.contentChange) { this.listener.contentChange() } diff --git a/src/editor/interface/Draw.ts b/src/editor/interface/Draw.ts index 13ba2cd..6b1cf20 100644 --- a/src/editor/interface/Draw.ts +++ b/src/editor/interface/Draw.ts @@ -8,6 +8,7 @@ export interface IDrawOption { isSubmitHistory?: boolean isCompute?: boolean isLazy?: boolean + isInit?: boolean } export interface IDrawImagePayload { diff --git a/src/main.ts b/src/main.ts index 8b0c3d3..8e80fd0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1432,7 +1432,7 @@ window.onload = function () { activeMode.classList.add('active') } - instance.listener.contentChange = debounce(async function () { + const handleContentChange = async function () { // 字数 const wordCount = await instance.command.getWordCount() document.querySelector('.word-count')!.innerText = `${ @@ -1442,7 +1442,9 @@ window.onload = function () { if (isCatalogShow) { updateCatalog() } - }, 200) + } + instance.listener.contentChange = debounce(handleContentChange, 200) + handleContentChange() instance.listener.saved = function (payload) { console.log('elementList: ', payload)