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: fix https://github.com/siyuan-note/siyuan/issues/9846
Vanessa2d11266b3134
diff --git a/app/src/constants.ts b/app/src/constants.tsindex 1d76f623df..97b01d7102 100644--- a/app/src/constants.ts+++ b/app/src/constants.ts@@ -100,6 +100,7 @@ export abstract class Constants {public static readonly LOCAL_AI = "local-ai";public static readonly LOCAL_PLUGINTOPUNPIN = "local-plugintopunpin";public static readonly LOCAL_FLASHCARD = "local-flashcard";+ public static readonly LOCAL_FILEPOSITION = "local-fileposition";// timeoutpublic static readonly TIMEOUT_DBLCLICK = 190;diff --git a/app/src/layout/tabUtil.ts b/app/src/layout/tabUtil.tsindex fad0deb4b2..f02dffd746 100644--- a/app/src/layout/tabUtil.ts+++ b/app/src/layout/tabUtil.ts@@ -231,11 +231,11 @@ export const copyTab = (app: App, tab: Tab) => {callback(newTab: Tab) {let model: Model;if (tab.model instanceof Editor) {+ saveScroll(tab.model.editor.protyle);model = new Editor({app,tab: newTab,- blockId: tab.model.editor.protyle.block.id,- scrollAttr: saveScroll(tab.model.editor.protyle, true)+ blockId: tab.model.editor.protyle.block.id});} else if (tab.model instanceof Asset) {model = new Asset({diff --git a/app/src/layout/util.ts b/app/src/layout/util.tsindex 3059fb1f7b..f5149838d5 100644--- a/app/src/layout/util.ts+++ b/app/src/layout/util.ts@@ -178,13 +178,12 @@ export const exportLayout = (options: {cb?: () => void,onlyData: boolean,errorExit: boolean,- dropEditScroll?: boolean}) => {if (isWindow()) {const layoutJSON: any = {layout: {},};- layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout, !!options.dropEditScroll);+ layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);if (options.onlyData) {return layoutJSON;}@@ -207,7 +206,7 @@ export const exportLayout = (options: {left: dockToJSON(window.siyuan.layout.leftDock),right: dockToJSON(window.siyuan.layout.rightDock),};- layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout, !!options.dropEditScroll);+ layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);if (options.onlyData) {return layoutJSON;}@@ -308,10 +307,6 @@ export const JSONToCenter = (app: App, json: ILayoutJSON, layout?: Layout | Wndif (window.siyuan.config.fileTree.openFilesUseCurrentTab) {(layout as Tab).headElement.classList.add("item--unupdate");}- if (json.scrollAttr) {- // 历史数据兼容- json.scrollAttr.rootId = json.rootId;- }(layout as Tab).headElement.setAttribute("data-initdata", JSON.stringify(json));} else if (json.instance === "Asset") {(layout as Tab).addModel(new Asset({@@ -431,7 +426,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => {resizeTopBar();};-export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any, dropEditScroll = false) => {+export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any) => {if (layout instanceof Layout) {json.direction = layout.direction;if (layout.parent) {@@ -480,9 +475,7 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any, dropjson.mode = layout.editor.protyle.preview.element.classList.contains("fn__none") ? "wysiwyg" : "preview";json.action = layout.editor.protyle.block.showAll ? Constants.CB_GET_ALL : "";json.instance = "Editor";- if (!dropEditScroll) {- json.scrollAttr = saveScroll(layout.editor.protyle, true);- }+ saveScroll(layout.editor.protyle);} else if (layout instanceof Asset) {json.path = layout.path;if (layout.pdfObject) {@@ -549,13 +542,13 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any, droplayout.children.forEach((item: Layout | Wnd | Tab) => {const itemJSON = {};json.children.push(itemJSON);- layoutToJSON(item, itemJSON, dropEditScroll);+ layoutToJSON(item, itemJSON);});}} else if (layout instanceof Tab) {if (layout.model) {json.children = {};- layoutToJSON(layout.model, json.children, dropEditScroll);+ layoutToJSON(layout.model, json.children);} else if (layout.headElement) {// 当前页签没有激活时编辑器没有初始化json.children = JSON.parse(layout.headElement.getAttribute("data-initdata") || "{}");diff --git a/app/src/protyle/scroll/saveScroll.ts b/app/src/protyle/scroll/saveScroll.tsindex 0188c78d3c..87149b468d 100644--- a/app/src/protyle/scroll/saveScroll.ts+++ b/app/src/protyle/scroll/saveScroll.ts@@ -3,6 +3,7 @@ import {getSelectionOffset} from "../util/selection";import {fetchPost} from "../../util/fetch";import {onGet} from "../util/onGet";import {Constants} from "../../constants";+import {setStorageVal} from "../util/compatibility";export const saveScroll = (protyle: IProtyle, getObject = false) => {if (!protyle.wysiwyg.element.firstElementChild || window.siyuan.config.readonly) {@@ -38,10 +39,8 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {if (getObject) {return attr;}- const jsonAttr = JSON.stringify(attr);- fetchPost("/api/attr/setBlockAttrs", {id: protyle.block.rootID, attrs: {scroll: jsonAttr}}, () => {- protyle.wysiwyg.element.setAttribute("scroll", jsonAttr);- });+ window.siyuan.storage[Constants.LOCAL_FILEPOSITION][protyle.block.rootID] = JSON.stringify(attr);+ setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION][protyle.block.rootID]);};export const getDocByScroll = (options: {diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.tsindex 10be7bfec9..f674bafaac 100644--- a/app/src/protyle/util/compatibility.ts+++ b/app/src/protyle/util/compatibility.ts@@ -187,6 +187,7 @@ export const getLocalStorage = (cb: () => void) => {defaultStorage[Constants.LOCAL_LAYOUTS] = []; // {name: "", layout:{}}defaultStorage[Constants.LOCAL_AI] = []; // {name: "", memo: ""}defaultStorage[Constants.LOCAL_PLUGINTOPUNPIN] = [];+ defaultStorage[Constants.LOCAL_FILEPOSITION] = {}; // {id: IScrollAttr}defaultStorage[Constants.LOCAL_FLASHCARD] = {fullscreen: false};@@ -244,7 +245,8 @@ export const getLocalStorage = (cb: () => void) => {[Constants.LOCAL_EXPORTIMG, Constants.LOCAL_SEARCHKEYS, Constants.LOCAL_PDFTHEME, Constants.LOCAL_BAZAAR,Constants.LOCAL_EXPORTWORD, Constants.LOCAL_EXPORTPDF, Constants.LOCAL_DOCINFO, Constants.LOCAL_FONTSTYLES,Constants.LOCAL_SEARCHDATA, Constants.LOCAL_ZOOM, Constants.LOCAL_LAYOUTS, Constants.LOCAL_AI,- Constants.LOCAL_PLUGINTOPUNPIN, Constants.LOCAL_SEARCHASSET, Constants.LOCAL_FLASHCARD].forEach((key) => {+ Constants.LOCAL_PLUGINTOPUNPIN, Constants.LOCAL_SEARCHASSET, Constants.LOCAL_FLASHCARD,+ Constants.LOCAL_FILEPOSITION].forEach((key) => {if (typeof response.data[key] === "string") {try {const parseData = JSON.parse(response.data[key]);@@ -262,14 +264,6 @@ export const getLocalStorage = (cb: () => void) => {}});cb();-- if (!window.siyuan.config.readonly) {- // 数据兼容,移除历史数据,3.8.4 移除- fetchPost("/api/storage/removeLocalStorageVals", {- app: Constants.SIYUAN_APPID,- keys: ["leftColumn", "local-searchkey", "local-searchedata", "local-searchekeys", "local-searchetabdata", "rightColumn", "topBar"]- });- }});};diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex 90ffdba888..1887d610d5 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -124,7 +124,7 @@ export class WYSIWYG {const ialKeys = Object.keys(ial);for (let i = 0; i < this.element.attributes.length; i++) {const oldKey = this.element.attributes[i].nodeName;- if (!["type", "class", "spellcheck", "contenteditable", "data-doc-type", "style", "scroll", "data-realwidth"].includes(oldKey) &&+ if (!["type", "class", "spellcheck", "contenteditable", "data-doc-type", "style", "data-realwidth"].includes(oldKey) &&!ialKeys.includes(oldKey)) {this.element.removeAttribute(oldKey);i--;diff --git a/app/src/util/backForward.ts b/app/src/util/backForward.tsindex ec631866f8..2e183f2f21 100644--- a/app/src/util/backForward.ts+++ b/app/src/util/backForward.ts@@ -52,10 +52,10 @@ const focusStack = async (app: App, stack: IBackStack) => {scrollAttr.focusId = stack.id;scrollAttr.focusStart = stack.position.start;scrollAttr.focusEnd = stack.position.end;+ window.siyuan.storage[Constants.LOCAL_FILEPOSITION][stack.protyle.block.rootID] = scrollAttr;const editor = new Editor({app: app,tab,- scrollAttr,blockId: stack.zoomId || stack.protyle.block.rootID,action: stack.zoomId ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS]});diff --git a/app/src/util/processMessage.ts b/app/src/util/processMessage.tsindex c1674aa20f..67c4883172 100644--- a/app/src/util/processMessage.ts+++ b/app/src/util/processMessage.ts@@ -2,6 +2,8 @@import {exportLayout} from "../layout/util";/// #endifimport {hideMessage, showMessage} from "../dialog/message";+import {setStorageVal} from "../protyle/util/compatibility";+import {Constants} from "../constants";export const processMessage = (response: IWebSocketData) => {if ("msg" === response.cmd) {@@ -20,6 +22,10 @@ export const processMessage = (response: IWebSocketData) => {return false;}if ("reloadui" === response.cmd) {+ if (response.data?.resetScroll) {+ window.siyuan.storage[Constants.LOCAL_FILEPOSITION] = {};+ setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]);+ }/// #if MOBILEwindow.location.reload();/// #else@@ -27,7 +33,6 @@ export const processMessage = (response: IWebSocketData) => {reload: true,onlyData: false,errorExit: false,- dropEditScroll: response.data?.resetScroll,});/// #endifreturn false;