An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:lipstick: https://github.com/siyuan-note/siyuan/issues/8219
Vanessa0daed2d12a0a
diff --git a/app/src/boot/globalShortcut.ts b/app/src/boot/globalShortcut.tsindex ce54aaffa7..ee29953f9c 100644--- a/app/src/boot/globalShortcut.ts+++ b/app/src/boot/globalShortcut.ts@@ -1044,7 +1044,7 @@ const editKeydown = (event: KeyboardEvent) => {return false;}if (matchHotKey(window.siyuan.config.keymap.editor.general.refresh.custom, event)) {- reloadProtyle(protyle);+ reloadProtyle(protyle, true);event.preventDefault();return true;}diff --git a/app/src/config/editor.ts b/app/src/config/editor.tsindex 73ea97eed9..5d8f8a0b54 100644--- a/app/src/config/editor.ts+++ b/app/src/config/editor.ts@@ -334,7 +334,7 @@ export const editor = {}window.siyuan.config.editor = editorData;getAllModels().editor.forEach((item) => {- reloadProtyle(item.editor.protyle);+ reloadProtyle(item.editor.protyle, false);setPadding(item.editor.protyle);if (window.siyuan.config.editor.fullWidth) {item.editor.protyle.contentElement.setAttribute("data-fullwidth", "true");diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.tsindex c9a6940ff7..78d18aa25b 100644--- a/app/src/dialog/processSystem.ts+++ b/app/src/dialog/processSystem.ts@@ -36,7 +36,7 @@ export const reloadSync = (data: { upsertRootIDs: string[], removeRootIDs: strinif (data.removeRootIDs.includes(window.siyuan.mobile.popEditor.protyle.block.rootID)) {hideElements(["dialog"]);} else {- reloadProtyle(window.siyuan.mobile.popEditor.protyle);+ reloadProtyle(window.siyuan.mobile.popEditor.protyle, false);window.siyuan.mobile.popEditor.protyle.breadcrumb.render(window.siyuan.mobile.popEditor.protyle, true);}}@@ -44,7 +44,7 @@ export const reloadSync = (data: { upsertRootIDs: string[], removeRootIDs: strinif (data.removeRootIDs.includes(window.siyuan.mobile.editor.protyle.block.rootID)) {setEmpty();} else {- reloadProtyle(window.siyuan.mobile.editor.protyle);+ reloadProtyle(window.siyuan.mobile.editor.protyle, false);fetchPost("/api/block/getDocInfo", {id: window.siyuan.mobile.editor.protyle.block.rootID}, (response) => {@@ -59,7 +59,7 @@ export const reloadSync = (data: { upsertRootIDs: string[], removeRootIDs: strinconst allModels = getAllModels();allModels.editor.forEach(item => {if (data.upsertRootIDs.includes(item.editor.protyle.block.rootID)) {- reloadProtyle(item.editor.protyle);+ reloadProtyle(item.editor.protyle, false);updateTitle(item.editor.protyle.block.rootID, item.parent);} else if (data.removeRootIDs.includes(item.editor.protyle.block.rootID)) {item.parent.parent.removeTab(item.parent.id, false, false, false);diff --git a/app/src/mobile/menu/search.ts b/app/src/mobile/menu/search.tsindex 3ce6da4f76..e5300565c6 100644--- a/app/src/mobile/menu/search.ts+++ b/app/src/mobile/menu/search.ts@@ -59,7 +59,7 @@ const replace = (element: Element, config: ISearchOption, isAll: boolean) => {if (ids.length > 1) {return;}- reloadProtyle(window.siyuan.mobile.editor.protyle);+ reloadProtyle(window.siyuan.mobile.editor.protyle, false);if (currentLiElement.nextElementSibling) {currentLiElement.nextElementSibling.classList.add("b3-list-item--focus");diff --git a/app/src/mobile/settings/editor.ts b/app/src/mobile/settings/editor.tsindex d2c77f404f..89fa9968d1 100644--- a/app/src/mobile/settings/editor.ts+++ b/app/src/mobile/settings/editor.ts@@ -40,7 +40,7 @@ const setEditor = (modelMainElement: Element) => {window.siyuan.config.editor.historyRetentionDays = parseInt((modelMainElement.querySelector("#historyRetentionDays") as HTMLInputElement).value);fetchPost("/api/setting/setEditor", window.siyuan.config.editor, response => {window.siyuan.config.editor = response.data;- reloadProtyle(window.siyuan.mobile.editor.protyle);+ reloadProtyle(window.siyuan.mobile.editor.protyle, false);setInlineStyle();});};diff --git a/app/src/protyle/breadcrumb/action.ts b/app/src/protyle/breadcrumb/action.tsindex 51764af089..218d69c611 100644--- a/app/src/protyle/breadcrumb/action.ts+++ b/app/src/protyle/breadcrumb/action.ts@@ -18,11 +18,11 @@ export const netImg2LocalAssets = (protyle: IProtyle) => {id: protyle.block.rootID}, () => {/// #if MOBILE- reloadProtyle(protyle);+ reloadProtyle(protyle, false);/// #elsegetAllModels().editor.forEach(item => {if (item.editor.protyle.block.rootID === protyle.block.rootID) {- reloadProtyle(item.editor.protyle)+ reloadProtyle(item.editor.protyle, item.editor.protyle.element.isSameNode(protyle.element));}});/// #endifdiff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.tsindex 5cb3efc83d..de73f34d4e 100644--- a/app/src/protyle/breadcrumb/index.ts+++ b/app/src/protyle/breadcrumb/index.ts@@ -245,11 +245,11 @@ export class Breadcrumb {id: protyle.block.rootID}, () => {/// #if MOBILE- reloadProtyle(protyle);+ reloadProtyle(protyle, false);/// #elsegetAllModels().editor.forEach(item => {if (item.editor.protyle.block.rootID === protyle.block.rootID) {- reloadProtyle(item.editor.protyle);+ reloadProtyle(item.editor.protyle, item.editor.protyle.element.isSameNode(protyle.element));}});/// #endif@@ -304,7 +304,7 @@ export class Breadcrumb {accelerator: window.siyuan.config.keymap.editor.general.refresh.custom,label: window.siyuan.languages.refresh,click: () => {- reloadProtyle(protyle);+ reloadProtyle(protyle, !isMobile());}}).element);window.siyuan.menus.menu.append(new MenuItem({diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.tsindex 15cd0195e8..282a80b10f 100644--- a/app/src/protyle/index.ts+++ b/app/src/protyle/index.ts@@ -27,6 +27,7 @@ import {reloadProtyle} from "./util/reload";import {renderBacklink} from "./wysiwyg/renderBacklink";import {setEmpty} from "../mobile/util/setEmpty";import {resize} from "./util/resize";+import {getDocByScroll} from "./scroll/saveScroll";export class Protyle {@@ -111,7 +112,7 @@ export class Protyle {onGet(getResponse, this.protyle);});} else {- reloadProtyle(this.protyle);+ reloadProtyle(this.protyle, false);}/// #if !MOBILEif (data.cmd === "heading2doc") {@@ -206,14 +207,28 @@ export class Protyle {scrollObj = undefined;}if (scrollObj) {- this.getDocByScrollData(scrollObj, mergedOptions);+ getDocByScroll({+ protyle: this.protyle,+ scrollAttr: scrollObj,+ mergedOptions,+ cb: () => {+ this.afterOnGet(mergedOptions);+ }+ });} else {this.getDoc(mergedOptions);}}});} else {- this.getDocByScrollData(options.scrollAttr, mergedOptions);+ getDocByScroll({+ protyle: this.protyle,+ scrollAttr: options.scrollAttr,+ mergedOptions,+ cb: () => {+ this.afterOnGet(mergedOptions);+ }+ });}} else {this.getDoc(mergedOptions);@@ -236,27 +251,6 @@ export class Protyle {});}- private getDocByScrollData(scrollAttr: IScrollAttr, mergedOptions: IOptions) {- if (scrollAttr.zoomInId) {- fetchPost("/api/filetree/getDoc", {- id: scrollAttr.zoomInId,- size: Constants.SIZE_GET_MAX,- }, response => {- onGet(response, this.protyle, mergedOptions.action, scrollAttr);- this.afterOnGet(mergedOptions);- })- return;- }- fetchPost("/api/filetree/getDoc", {- id: scrollAttr.startId,- startID: scrollAttr.startId,- endID: scrollAttr.endId,- }, response => {- onGet(response, this.protyle, mergedOptions.action, scrollAttr);- this.afterOnGet(mergedOptions);- });- }-private afterOnGet(mergedOptions: IOptions) {if (this.protyle.model) {/// #if !MOBILEdiff --git a/app/src/protyle/scroll/saveScroll.ts b/app/src/protyle/scroll/saveScroll.tsindex 6ecb81015b..49c3ceef7f 100644--- a/app/src/protyle/scroll/saveScroll.ts+++ b/app/src/protyle/scroll/saveScroll.ts@@ -1,14 +1,8 @@import {hasClosestBlock} from "../util/hasClosest";import {focusByOffset, getSelectionOffset} from "../util/selection";import {fetchPost} from "../../util/fetch";-import {zoomOut} from "../../menus/protyle";-import {preventScroll} from "./preventScroll";-import {pushBack} from "../../util/backForward";-import {processRender} from "../util/processCode";-import {highlightRender} from "../markdown/highlightRender";-import {blockRender} from "../markdown/blockRender";-import {disabledForeverProtyle, disabledProtyle, enableProtyle} from "../util/onGet";-import {showMessage} from "../../dialog/message";+import {onGet} from "../util/onGet";+import {Constants} from "../../constants";export const saveScroll = (protyle: IProtyle, getObject = false) => {if (!protyle.wysiwyg.element.firstElementChild || window.siyuan.config.readonly) {@@ -49,66 +43,45 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {});};-export const restoreScroll = (protyle: IProtyle, scrollAttr: IScrollAttr) => {- preventScroll(protyle);- if (protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id") === scrollAttr.startId &&- protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id") === scrollAttr.endId) {- // 需等动画效果完毕,才能获得最大高度。否则尾部定位无法滚动到底部- setTimeout(() => {- protyle.contentElement.scrollTop = scrollAttr.scrollTop;- }, 256);- if (scrollAttr.focusId) {- const range = focusByOffset(protyle.wysiwyg.element.querySelector(`[data-node-id="${scrollAttr.focusId}"]`), scrollAttr.focusStart, scrollAttr.focusEnd);- /// #if !MOBILE- pushBack(protyle, range || undefined);- /// #endif+export const getDocByScroll = (options: {+ protyle: IProtyle,+ scrollAttr: IScrollAttr,+ mergedOptions?: IOptions,+ cb?: () => void+ focus?: boolean+}) => {+ let actions: string[] = []+ if (options.mergedOptions) {+ actions = options.mergedOptions.action+ } else {+ if (options.focus) {+ actions = [Constants.CB_GET_UNUNDO, Constants.CB_GET_FOCUS]+ } else {+ actions = [Constants.CB_GET_UNUNDO];}- } else if (scrollAttr.zoomInId && protyle.block.id !== scrollAttr.zoomInId) {- fetchPost("/api/block/checkBlockExist", {id: scrollAttr.zoomInId}, existResponse => {- if (existResponse.data) {- zoomOut(protyle, scrollAttr.zoomInId, undefined, true, () => {- protyle.contentElement.scrollTop = scrollAttr.scrollTop;- if (scrollAttr.focusId) {- focusByOffset(protyle.wysiwyg.element.querySelector(`[data-node-id="${scrollAttr.focusId}"]`), scrollAttr.focusStart, scrollAttr.focusEnd);- }- });- }- });- } else if (!protyle.scroll.element.classList.contains("fn__none")) {+ if (options.scrollAttr.zoomInId) {+ actions.push(Constants.CB_GET_ALL);+ }+ }+ if (options.scrollAttr.zoomInId) {fetchPost("/api/filetree/getDoc", {- id: protyle.block.id,- startID: scrollAttr.startId,- endID: scrollAttr.endId,- }, getResponse => {- protyle.block.showAll = false;- protyle.wysiwyg.element.innerHTML = getResponse.data.content;- processRender(protyle.wysiwyg.element);- highlightRender(protyle.wysiwyg.element);- blockRender(protyle, protyle.wysiwyg.element);- if (getResponse.data.isSyncing) {- disabledForeverProtyle(protyle);- } else {- if (protyle.disabled) {- disabledProtyle(protyle);- } else {- enableProtyle(protyle);- }- }- protyle.contentElement.scrollTop = scrollAttr.scrollTop;- if (scrollAttr.focusId) {- const range = focusByOffset(protyle.wysiwyg.element.querySelector(`[data-node-id="${scrollAttr.focusId}"]`), scrollAttr.focusStart, scrollAttr.focusEnd);- /// #if !MOBILE- pushBack(protyle, range || undefined);- /// #endif- }- // 使用动态滚动条定位到最后一个块,重启后无法触发滚动事件,需要再次更新 index- protyle.scroll.updateIndex(protyle, scrollAttr.startId);- // https://github.com/siyuan-note/siyuan/issues/8224- if (protyle.wysiwyg.element.clientHeight - parseInt(protyle.wysiwyg.element.style.paddingBottom) < protyle.contentElement.clientHeight) {- showMessage(window.siyuan.languages.scrollGetMore);+ id: options.scrollAttr.zoomInId,+ size: Constants.SIZE_GET_MAX,+ }, response => {+ onGet(response, options.protyle, actions, options.scrollAttr);+ if (options.cb) {+ options.cb()}});- } else if (scrollAttr.scrollTop) {- protyle.contentElement.scrollTop = scrollAttr.scrollTop;}+ fetchPost("/api/filetree/getDoc", {+ id: options.scrollAttr.startId,+ startID: options.scrollAttr.startId,+ endID: options.scrollAttr.endId,+ }, response => {+ onGet(response, options.protyle, actions, options.scrollAttr);+ if (options.cb) {+ options.cb()+ }+ });};diff --git a/app/src/protyle/util/reload.ts b/app/src/protyle/util/reload.tsindex b93d6713f0..f1c3e4378b 100644--- a/app/src/protyle/util/reload.ts+++ b/app/src/protyle/util/reload.ts@@ -1,12 +1,11 @@import {addLoading} from "../ui/initUI";import {fetchPost} from "../../util/fetch";-import {Constants} from "../../constants";-import {onGet} from "./onGet";-import {saveScroll} from "../scroll/saveScroll";+import {getDocByScroll, saveScroll} from "../scroll/saveScroll";import {renderBacklink} from "../wysiwyg/renderBacklink";import {hasClosestByClassName} from "./hasClosest";+import {preventScroll} from "../scroll/preventScroll";-export const reloadProtyle = (protyle: IProtyle) => {+export const reloadProtyle = (protyle: IProtyle, focus: boolean) => {if (window.siyuan.config.editor.displayBookmarkIcon) {protyle.wysiwyg.element.classList.add("protyle-wysiwyg--attr");} else {@@ -38,12 +37,11 @@ export const reloadProtyle = (protyle: IProtyle) => {});}} else {- fetchPost("/api/filetree/getDoc", {- id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID,- mode: 0,- size: protyle.block.showAll ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,- }, getResponse => {- onGet(getResponse, protyle, protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS], saveScroll(protyle, true), true);+ preventScroll(protyle);+ getDocByScroll({+ protyle,+ focus,+ scrollAttr: saveScroll(protyle, true)});}};diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.tsindex 5f1d5bc396..b2301b46f2 100644--- a/app/src/protyle/wysiwyg/transaction.ts+++ b/app/src/protyle/wysiwyg/transaction.ts@@ -647,7 +647,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: breturn;}if (operation.action === "append") {- reloadProtyle(protyle);+ reloadProtyle(protyle, false);}};diff --git a/app/src/search/util.ts b/app/src/search/util.tsindex fe3574c933..1ccb6a97a1 100644--- a/app/src/search/util.ts+++ b/app/src/search/util.ts@@ -961,7 +961,7 @@ const replace = (element: Element, config: ISearchOption, edit: Protyle, isAll:}getAllModels().editor.forEach(item => {if (rootIds[0] === item.editor.protyle.block.rootID) {- reloadProtyle(item.editor.protyle);+ reloadProtyle(item.editor.protyle, false);}});if (currentList.nextElementSibling) {