An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: https://github.com/siyuan-note/siyuan/pull/17572
Vanessa3dbacc89d7dd
diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.tsindex 88e96e1f36..398da31747 100644--- a/app/src/layout/Wnd.ts+++ b/app/src/layout/Wnd.ts@@ -772,9 +772,6 @@ export class Wnd {if (item.id !== id) {return;}- if (item.model instanceof Editor) {- clearCounter(item.model.editor.protyle.block.rootID);- }if (window.siyuan.storage[Constants.LOCAL_CLOSED_TABS].length > Constants.SIZE_UNDO) {window.siyuan.storage[Constants.LOCAL_CLOSED_TABS].pop();}@@ -871,6 +868,7 @@ export class Wnd {const wnd = new Wnd(this.app);window.siyuan.layout.centerLayout.addWnd(wnd);wnd.addTab(newCenterEmptyTab(this.app), false, false);+ clearCounter();setTitle("", true);}}diff --git a/app/src/layout/status.ts b/app/src/layout/status.tsindex 294fa64ac2..b3939e3bbf 100644--- a/app/src/layout/status.ts+++ b/app/src/layout/status.ts@@ -135,10 +135,9 @@ export const initStatus = (isWindow = false) => {let countTimeout: number;let countAbortController: AbortController | null = null;-let statusStatRootId: string; // 状态栏最后显示的统计信息所属文档 ID+let lastRootId: string;const scheduleStatusStat = (rootID: string, content?: string, ids?: string[]) => {- statusStatRootId = rootID;clearTimeout(countTimeout);countTimeout = window.setTimeout(() => {if (countAbortController) {@@ -161,15 +160,20 @@ const scheduleStatusStat = (rootID: string, content?: string, ids?: string[]) =>if (content) {fetchPost("/api/block/getContentWordCount", {content}, onFetched, undefined, undefined, signal);+ lastRootId = null;} else if (ids && ids.length > 0) {fetchPost("/api/block/getBlocksWordCount", {ids}, onFetched, undefined, undefined, signal);- } else {+ lastRootId = null;+ } else if (rootID && lastRootId !== rootID) {+ lastRootId = rootID;fetchPost("/api/block/getTreeStat", {id: rootID}, onFetched, undefined, undefined, signal);+ } else {+ lastRootId = null;}}, Constants.TIMEOUT_COUNT);};-export const countSelectWord = (range: Range, rootID: string) => {+export const countSelectWord = (range: Range, rootID?: string) => {/// #if !MOBILEif (document.getElementById("status").classList.contains("fn__none")) {return;@@ -178,12 +182,14 @@ export const countSelectWord = (range: Range, rootID: string) => {/// #endif};-export const countBlockWord = (ids: string[], rootID: string) => {+export const countBlockWord = (ids: string[], rootID?: string, clearCache = false) => {/// #if !MOBILEif (document.getElementById("status").classList.contains("fn__none")) {return;}- ids = ids.filter((id) => Boolean(id));+ if (clearCache) {+ lastRootId = null;+ }if (ids.length > 0) {scheduleStatusStat(rootID, undefined, ids);return;@@ -197,11 +203,8 @@ export const countBlockWord = (ids: string[], rootID: string) => {/// #endif};-export const clearCounter = (rootID: string) => {- if (statusStatRootId !== rootID) {- return;- }- statusStatRootId = undefined;+export const clearCounter = () => {+ lastRootId = null;clearTimeout(countTimeout);if (countAbortController) {countAbortController.abort();diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex ab1c445dbd..421b86790a 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -281,7 +281,7 @@ export class WYSIWYG {if (selectElements.length === 0 && range.toString() === "" && !range.cloneContents().querySelector("img") &&!selectImgElement && !selectAVElement && !selectTableElement) {nodeElement.classList.add("protyle-wysiwyg--select");- countBlockWord([nodeElement.getAttribute("data-node-id")], protyle.block.rootID);+ countBlockWord([nodeElement.getAttribute("data-node-id")]);selectElements = [nodeElement];}let html = "";@@ -657,7 +657,7 @@ export class WYSIWYG {});}});- countBlockWord(ids, protyle.block.rootID);+ countBlockWord(ids);if (toDown) {focusBlock(selectElements[selectElements.length - 1], protyle.wysiwyg.element, false);} else {@@ -706,7 +706,7 @@ export class WYSIWYG {protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").forEach(item => {ids.push(item.getAttribute("data-node-id"));});- countBlockWord(ids, protyle.block.rootID);+ countBlockWord(ids);}return;}@@ -1739,7 +1739,7 @@ export class WYSIWYG {selectElement.forEach(item => {ids.push(item.getAttribute("data-node-id"));});- countBlockWord(ids, protyle.block.rootID);+ countBlockWord(ids);// 划选后不能存在跨块的 range https://github.com/siyuan-note/siyuan/issues/4473if (getSelection().rangeCount > 0) {const range = getSelection().getRangeAt(0);@@ -2584,7 +2584,7 @@ export class WYSIWYG {if ((event.shiftKey || isOnlyMeta(event)) && !event.isComposing && range.toString() !== "") {// 工具栏protyle.toolbar.render(protyle, range, event);- countSelectWord(range, protyle.block.rootID);+ countSelectWord(range);}if (event.eventPhase !== 3 && !event.shiftKey && (event.key.indexOf("Arrow") > -1 || event.key === "Home" || event.key === "End" || event.key === "PageUp" || event.key === "PageDown") && !event.isComposing) {diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.tsindex 4811919a06..24933b682b 100644--- a/app/src/protyle/wysiwyg/keydown.ts+++ b/app/src/protyle/wysiwyg/keydown.ts@@ -240,7 +240,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {}nextElement.classList.add("protyle-wysiwyg--select");- countBlockWord([nextElement.getAttribute("data-node-id")], protyle.block.rootID);+ countBlockWord([nextElement.getAttribute("data-node-id")]);const bottom = nextElement.getBoundingClientRect().bottom - protyle.contentElement.getBoundingClientRect().bottom;if (bottom > 0) {protyle.contentElement.scrollTop = protyle.contentElement.scrollTop + bottom;@@ -281,7 +281,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {}if (previousElement) {previousElement.classList.add("protyle-wysiwyg--select");- countBlockWord([previousElement.getAttribute("data-node-id")], protyle.block.rootID);+ countBlockWord([previousElement.getAttribute("data-node-id")]);const top = previousElement.getBoundingClientRect().top - protyle.contentElement.getBoundingClientRect().top;if (top < 0) {protyle.contentElement.scrollTop = protyle.contentElement.scrollTop + top;@@ -510,7 +510,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {ids.push(nextElement.getAttribute("data-node-id"));nextElement = event.key === "Home" ? nextElement.previousElementSibling : nextElement.nextElementSibling;}- countBlockWord(ids, protyle.block.rootID);+ countBlockWord(ids);if (event.key === "Home") {protyle.wysiwyg.element.firstElementChild.scrollIntoView();} else {diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.tsindex 39ef3b0e12..a0a6a7253f 100644--- a/app/src/protyle/wysiwyg/transaction.ts+++ b/app/src/protyle/wysiwyg/transaction.ts@@ -85,7 +85,7 @@ const promiseTransaction = () => {protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").forEach(item => {ids.push(item.getAttribute("data-node-id"));});- countBlockWord(ids, protyle.block.rootID);+ countBlockWord(ids, protyle.block.rootID, true);} else {promiseTransaction();}