An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: fix https://github.com/siyuan-note/siyuan/issues/5767
Vanessa194a18fc9519
diff --git a/app/src/config/editor.ts b/app/src/config/editor.tsindex 736a7b22c1..faa4b85e05 100644--- a/app/src/config/editor.ts+++ b/app/src/config/editor.ts@@ -3,6 +3,7 @@ import {setInlineStyle} from "../util/assets";import {fetchPost} from "../util/fetch";import {confirmDialog} from "../dialog/confirmDialog";import {setPadding} from "../protyle/ui/initUI";+import {reloadProtyle} from "../protyle/util/reload";export const editor = {element: undefined as Element,@@ -201,7 +202,7 @@ export const editor = {onSetEditor: (editor: IEditor) => {window.siyuan.config.editor = editor;getAllModels().editor.forEach((item) => {- item.editor.reload();+ reloadProtyle(item.editor.protyle)setPadding(item.editor.protyle);if (window.siyuan.config.editor.fullWidth) {item.editor.protyle.contentElement.setAttribute("data-fullwidth", "true");diff --git a/app/src/mobile/settings/appearance.ts b/app/src/mobile/settings/appearance.tsindex 540049b1c7..05ff1e0e6a 100644--- a/app/src/mobile/settings/appearance.ts+++ b/app/src/mobile/settings/appearance.ts@@ -2,6 +2,7 @@ import {closePanel} from "../util/closePanel";import {fetchPost} from "../../util/fetch";import {setInlineStyle} from "../../util/assets";import {genOptions} from "../../util/genOptions";+import {reloadProtyle} from "../../protyle/util/reload";export const initAppearance = (modelElement: HTMLElement, modelMainElement: HTMLElement) => {closePanel();@@ -69,7 +70,7 @@ export const initAppearance = (modelElement: HTMLElement, modelMainElement: HTMLemoji: window.siyuan.config.editor.emoji}, (response) => {window.siyuan.config.editor = response.data;- window.siyuan.mobileEditor.reload();+ reloadProtyle(window.siyuan.mobileEditor.protyle);setInlineStyle();});});diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.tsindex 20d556065f..6847ad442f 100644--- a/app/src/protyle/index.ts+++ b/app/src/protyle/index.ts@@ -2,7 +2,7 @@ import {Constants} from "../constants";import {Hint} from "./hint";import {setLute} from "./markdown/setLute";import {Preview} from "./preview";-import {addLoading, initUI, setPadding} from "./ui/initUI";+import {initUI, setPadding} from "./ui/initUI";import {Undo} from "./undo";import {Upload} from "./upload";import {Options} from "./util/Options";@@ -24,6 +24,7 @@ import {setPanelFocus} from "../layout/util";import {Background} from "./header/Background";import {getDisplayName} from "../util/pathName";import {onGet} from "./util/onGet";+import {reloadProtyle} from "./util/reload";class Protyle {@@ -93,24 +94,22 @@ class Protyle {case "heading2doc":case "li2doc":if (this.protyle.block.rootID === data.data.srcRootBlockID) {- const scrollTop = this.protyle.contentElement.scrollTop;- fetchPost("/api/filetree/getDoc", {- id: this.protyle.block.id,- size: Constants.SIZE_GET,- }, getResponse => {- onGet(getResponse, this.protyle);- /// #if !MOBILE- if (data.cmd === "heading2doc") {- // 文档标题互转后,需更新大纲- updatePanelByEditor(this.protyle, false, false, true);- }- /// #endif- // 文档标题互转后,编辑区会跳转到开头 https://github.com/siyuan-note/siyuan/issues/2939- setTimeout(() => {- this.protyle.contentElement.scrollTop = scrollTop;- this.protyle.scroll.lastScrollTop = scrollTop - 1;- }, Constants.TIMEOUT_BLOCKLOAD);- });+ if (this.protyle.block.showAll && data.cmd === "heading2doc") {+ fetchPost("/api/filetree/getDoc", {+ id: this.protyle.block.rootID,+ size: Constants.SIZE_GET,+ }, getResponse => {+ onGet(getResponse, this.protyle);+ })+ } else {+ reloadProtyle(this.protyle);+ }+ /// #if !MOBILE+ if (data.cmd === "heading2doc") {+ // 文档标题互转后,需更新大纲+ updatePanelByEditor(this.protyle, false, false, true);+ }+ /// #endif}break;case "rename":@@ -206,23 +205,6 @@ class Protyle {}}- public reload() {- if (window.siyuan.config.editor.displayBookmarkIcon) {- this.protyle.wysiwyg.element.classList.add("protyle-wysiwyg--attr");- } else {- this.protyle.wysiwyg.element.classList.remove("protyle-wysiwyg--attr");- }- this.protyle.lute.SetProtyleMarkNetImg(window.siyuan.config.editor.displayNetImgMark);- addLoading(this.protyle);- fetchPost("/api/filetree/getDoc", {- id: this.protyle.block.id,- mode: 0,- size: Constants.SIZE_GET,- }, getResponse => {- onGet(getResponse, this.protyle);- });- }-private init() {this.protyle.lute = setLute({emojiSite: this.protyle.options.hint.emojiPath,diff --git a/app/src/protyle/scroll/saveScroll.ts b/app/src/protyle/scroll/saveScroll.tsindex 42ff6cf5a5..9a35111934 100644--- a/app/src/protyle/scroll/saveScroll.ts+++ b/app/src/protyle/scroll/saveScroll.ts@@ -97,5 +97,7 @@ export const restoreScroll = (protyle: IProtyle, scrollAttr: IScrollAttr) => {/// #endif}});+ } else if (scrollAttr.scrollTop) {+ protyle.contentElement.scrollTop = scrollAttr.scrollTop;}};diff --git a/app/src/protyle/util/reload.ts b/app/src/protyle/util/reload.tsnew file mode 100644index 0000000000..c7202a4329--- /dev/null+++ b/app/src/protyle/util/reload.ts@@ -0,0 +1,22 @@+import {addLoading} from "../ui/initUI";+import {fetchPost} from "../../util/fetch";+import {Constants} from "../../constants";+import {onGet} from "./onGet";+import {saveScroll} from "../scroll/saveScroll";++export const reloadProtyle = (protyle:IProtyle) => {+ if (window.siyuan.config.editor.displayBookmarkIcon) {+ protyle.wysiwyg.element.classList.add("protyle-wysiwyg--attr");+ } else {+ protyle.wysiwyg.element.classList.remove("protyle-wysiwyg--attr");+ }+ protyle.lute.SetProtyleMarkNetImg(window.siyuan.config.editor.displayNetImgMark);+ addLoading(protyle);+ fetchPost("/api/filetree/getDoc", {+ id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID,+ mode: 0,+ size: protyle.block.showAll ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,+ }, getResponse => {+ onGet(getResponse, protyle, protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS], saveScroll(protyle, true), true);+ });+}diff --git a/app/src/protyle/wysiwyg/commonHotkey.ts b/app/src/protyle/wysiwyg/commonHotkey.tsindex 39cd07b10c..80293c256a 100644--- a/app/src/protyle/wysiwyg/commonHotkey.ts+++ b/app/src/protyle/wysiwyg/commonHotkey.ts@@ -3,11 +3,9 @@ import {fetchPost} from "../../util/fetch";import {writeText} from "../util/compatibility";import {focusByOffset, getSelectionOffset} from "../util/selection";import {fullscreen, netImg2LocalAssets} from "../breadcrumb/action";-import {addLoading, setPadding} from "../ui/initUI";-import {Constants} from "../../constants";-import {onGet} from "../util/onGet";+import {setPadding} from "../ui/initUI";import {openBacklink, openGraph, openOutline} from "../../layout/dock/util";-import {saveScroll} from "../scroll/saveScroll";+import {reloadProtyle} from "../util/reload";export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent) => {const target = event.target as HTMLElement;@@ -23,14 +21,7 @@ export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent) => {}if (matchHotKey(window.siyuan.config.keymap.editor.general.refresh.custom, event)) {- addLoading(protyle);- fetchPost("/api/filetree/getDoc", {- id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID,- mode: 0,- size: protyle.block.showAll ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,- }, getResponse => {- onGet(getResponse, protyle, protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS], saveScroll(protyle, true), true);- });+ reloadProtyle(protyle);event.preventDefault();event.stopPropagation();return true;diff --git a/app/src/search/spread.ts b/app/src/search/spread.tsindex fb9eeb40d4..826886492c 100644--- a/app/src/search/spread.ts+++ b/app/src/search/spread.ts@@ -11,6 +11,7 @@ import {addLoading} from "../protyle/ui/initUI";import {getAllModels} from "../layout/getAll";import {showMessage} from "../dialog/message";import {focusByRange} from "../protyle/util/selection";+import {reloadProtyle} from "../protyle/util/reload";let protyle: Protyle;export const openSearch = async (hotkey: string, key?: string, notebookId?: string, searchPath?: string) => {@@ -536,7 +537,7 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri}getAllModels().editor.forEach(item => {if (rootIds[0] === item.editor.protyle.block.rootID) {- item.editor.reload();+ reloadProtyle(item.editor.protyle)}});if (!currentList.nextElementSibling && searchPanelElement.children[0]) {