Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: fix https://github.com/siyuan-note/insider/issues/1093

Vanessa72a671ab787c
diff --git a/app/src/layout/status.ts b/app/src/layout/status.ts
index ae293f2a3f..6debbea143 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 7385f3e662..fca7f9a58c 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