From 72a671ab787c988276a1dc1c4a0d11c1e2560ed5 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 7 Oct 2022 20:56:19 +0800 Subject: [PATCH] :bug: fix https://github.com/siyuan-note/insider/issues/1093 --- app/src/layout/status.ts | 10 ++++++++-- app/src/protyle/wysiwyg/index.ts | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/layout/status.ts b/app/src/layout/status.ts index ae293f2a3..6debbea14 100644 --- a/app/src/layout/status.ts +++ b/app/src/layout/status.ts @@ -129,6 +129,7 @@ export const initStatus = () => { /// #endif }; +let countRootId: string export const countSelectWord = (range: Range, rootID?: string) => { /// #if !MOBILE if (document.getElementById("status").classList.contains("fn__none")) { @@ -139,7 +140,9 @@ export const countSelectWord = (range: Range, rootID?: string) => { fetchPost("/api/block/getContentWordCount", {"content": range.toString()}, (response) => { renderStatusbarCounter(response.data); }); - } else if (rootID) { + countRootId = "" + } else if (rootID && rootID !== countRootId) { + countRootId = rootID; fetchPost("/api/block/getTreeStat", {id: rootID}, (response) => { renderStatusbarCounter(response.data); }); @@ -156,7 +159,9 @@ export const countBlockWord = (ids: string[], rootID?: string) => { fetchPost("/api/block/getBlocksWordCount", {ids}, (response) => { renderStatusbarCounter(response.data); }); - } else if (rootID) { + countRootId = "" + } else if (rootID && rootID !== countRootId) { + countRootId = rootID fetchPost("/api/block/getTreeStat", {id: rootID}, (response) => { renderStatusbarCounter(response.data); }); @@ -165,6 +170,7 @@ export const countBlockWord = (ids: string[], rootID?: string) => { }; export const clearCounter = () => { + countRootId = "" document.querySelector("#status .status__counter").innerHTML = ""; }; diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index 7385f3e66..fca7f9a58 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -1381,6 +1381,9 @@ export class WYSIWYG { const nodeElement = hasClosestBlock(range.startContainer); if (nodeElement) { this.setEmptyOutline(protyle, nodeElement); + if (range.toString() === "") { + countSelectWord(range, protyle.block.rootID); + } } event.stopPropagation(); } @@ -1807,7 +1810,7 @@ export class WYSIWYG { hideElements(["toolbar"], protyle); } if (!protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select")) { - countSelectWord(newRange); + countSelectWord(newRange, protyle.block.rootID); } if (getSelection().rangeCount === 0) { // https://github.com/siyuan-note/siyuan/issues/5901