An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:zap: 获取 json 布局不应保存 scroll
Vanessaac269b4e1b37
diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.tsindex a45e2eecb3..a649d3746c 100644--- a/app/src/boot/globalEvent/keydown.ts+++ b/app/src/boot/globalEvent/keydown.ts@@ -144,7 +144,7 @@ const dialogArrow = (app: App, element: HTMLElement, event: KeyboardEvent) => {openFileById({app,id: currentLiElement.getAttribute("data-node-id"),- action: [Constants.CB_GET_SCROLL]+ action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]});}hideElements(["dialog"]);diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.tsindex 9ab92cdf80..4f8e1af63c 100644--- a/app/src/boot/onGetConfig.ts+++ b/app/src/boot/onGetConfig.ts@@ -176,7 +176,6 @@ export const initWindow = async (app: App) => {/// #if !BROWSERconst winOnClose = (close = false) => {exportLayout({- reload: false,cb() {if (window.siyuan.config.appearance.closeButtonBehavior === 1 && !close) {// 最小化@@ -191,7 +190,6 @@ export const initWindow = async (app: App) => {exitSiYuan();}},- onlyData: false,errorExit: true});};diff --git a/app/src/config/about.ts b/app/src/config/about.tsindex 50633d8ebe..a1d9a86be0 100644--- a/app/src/config/about.ts+++ b/app/src/config/about.ts@@ -306,8 +306,6 @@ export const about = {networkServeElement.addEventListener("change", () => {fetchPost("/api/system/setNetworkServe", {networkServe: networkServeElement.checked}, () => {exportLayout({- reload: false,- onlyData: false,errorExit: true,cb: exitSiYuan});@@ -323,9 +321,10 @@ export const about = {googleAnalyticsElement.addEventListener("change", () => {fetchPost("/api/system/setGoogleAnalytics", {googleAnalytics: googleAnalyticsElement.checked}, () => {exportLayout({- reload: true,- onlyData: false,errorExit: false,+ cb() {+ window.location.reload();+ }});});});@@ -333,8 +332,6 @@ export const about = {uploadErrLogElement.addEventListener("change", () => {fetchPost("/api/system/setUploadErrLog", {uploadErrLog: uploadErrLogElement.checked}, () => {exportLayout({- reload: false,- onlyData: false,errorExit: true,cb: exitSiYuan});@@ -369,9 +366,10 @@ export const about = {proxyURL: `${window.siyuan.config.system.networkProxy.scheme}://${window.siyuan.config.system.networkProxy.host}:${window.siyuan.config.system.networkProxy.port}`,}).then(() => {exportLayout({- reload: true,- onlyData: false,errorExit: false,+ cb() {+ window.location.reload();+ },});});/// #endifdiff --git a/app/src/config/appearance.ts b/app/src/config/appearance.tsindex 153e2e41ea..01ee18d692 100644--- a/app/src/config/appearance.ts+++ b/app/src/config/appearance.ts@@ -169,9 +169,10 @@ export const appearance = {window.siyuan.config.appearance.themeDark !== response.data.themeDark)) {exportLayout({- reload: true,- onlyData: false,errorExit: false,+ cb() {+ window.location.reload();+ },});return;}@@ -180,8 +181,9 @@ export const appearance = {(response.data.mode === 1 && OSTheme === "light") || (response.data.mode === 0 && OSTheme === "dark"))) {exportLayout({- reload: true,- onlyData: false,+ cb() {+ window.location.reload();+ },errorExit: false,});return;@@ -215,8 +217,9 @@ export const appearance = {});appearance.element.querySelector("#appearanceRefresh").addEventListener("click", () => {exportLayout({- reload: true,- onlyData: false,+ cb() {+ window.location.reload();+ },errorExit: false,});});@@ -235,8 +238,9 @@ export const appearance = {onSetappearance(data: IAppearance) {if (data.lang !== window.siyuan.config.appearance.lang) {exportLayout({- reload: true,- onlyData: false,+ cb() {+ window.location.reload();+ },errorExit: false,});return;diff --git a/app/src/config/bazaar.ts b/app/src/config/bazaar.tsindex cc04415447..510efa8f25 100644--- a/app/src/config/bazaar.ts+++ b/app/src/config/bazaar.ts@@ -626,8 +626,9 @@ export const bazaar = {}, response => {if (window.siyuan.config.appearance.themeJS && bazaarType === "themes") {exportLayout({- reload: true,- onlyData: false,+ cb() {+ window.location.reload();+ },errorExit: false,});return;@@ -686,8 +687,9 @@ export const bazaar = {)) {if (window.siyuan.config.appearance.themeJS) {exportLayout({- reload: true,- onlyData: false,+ cb() {+ window.location.reload();+ },errorExit: false,});} else {@@ -763,8 +765,9 @@ export const bazaar = {(mode === 0 && window.siyuan.config.appearance.themeLight !== packageName)) &&window.siyuan.config.appearance.themeJS) {exportLayout({- reload: true,- onlyData: false,+ cb() {+ window.location.reload();+ },errorExit: false,});} else {diff --git a/app/src/config/keymap.ts b/app/src/config/keymap.tsindex 45371b892e..64f4cee260 100644--- a/app/src/config/keymap.ts+++ b/app/src/config/keymap.ts@@ -259,8 +259,9 @@ export const keymap = {bindEvent(app: App) {keymap.element.querySelector("#keymapRefreshBtn").addEventListener("click", () => {exportLayout({- reload: true,- onlyData: false,+ cb() {+ window.location.reload();+ },errorExit: false,});});diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.tsindex 1834b8fde9..c1faa4a32e 100644--- a/app/src/dialog/processSystem.ts+++ b/app/src/dialog/processSystem.ts@@ -263,8 +263,6 @@ export const transactionError = () => {exitSiYuan();/// #elseexportLayout({- reload: false,- onlyData: false,errorExit: true,cb: exitSiYuan});diff --git a/app/src/layout/topBar.ts b/app/src/layout/topBar.tsindex 06e6651a51..1861c493c9 100644--- a/app/src/layout/topBar.ts+++ b/app/src/layout/topBar.ts@@ -117,10 +117,8 @@ export const initBar = (app: App) => {break;} else if (targetId === "barExit") {exportLayout({- reload: false,- onlyData: false,errorExit: true,- cb: exitSiYuan+ cb: exitSiYuan,});event.stopPropagation();break;diff --git a/app/src/layout/util.ts b/app/src/layout/util.tsindex cf0fe5890b..a95ca8c909 100644--- a/app/src/layout/util.ts+++ b/app/src/layout/util.ts@@ -220,25 +220,19 @@ export const saveLayout = () => {};export const exportLayout = (options: {- reload: boolean,- cb?: () => void,- onlyData: boolean,- errorExit: boolean,+ cb: () => void,+ errorExit: boolean}) => {if (isWindow()) {const layoutJSON: any = {layout: {},};layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);- if (options.onlyData) {- return layoutJSON;- }+ getAllModels().editor.forEach(item => {+ saveScroll(item.editor.protyle)+ })sessionStorage.setItem("layout", JSON.stringify(layoutJSON));- if (options.reload) {- window.location.reload();- } else if (options.cb) {- options.cb();- }+ options.cb();return;}const useElement = document.querySelector("#barDock use");@@ -253,21 +247,29 @@ export const exportLayout = (options: {right: dockToJSON(window.siyuan.layout.rightDock),};layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);- if (options.onlyData) {- return layoutJSON;- }+ getAllModels().editor.forEach(item => {+ saveScroll(item.editor.protyle)+ })fetchPost("/api/system/setUILayout", {layout: layoutJSON,errorExit: options.errorExit // 后台不接受该参数,用于请求发生错误时退出程序}, () => {- if (options.reload) {- window.location.reload();- } else if (options.cb) {- options.cb();- }+ options.cb();});};+export const getAllLayout = () => {+ const layoutJSON: any = {+ hideDock: document.querySelector("#barDock use").getAttribute("xlink:href") === "#iconDock",+ layout: {},+ bottom: dockToJSON(window.siyuan.layout.bottomDock),+ left: dockToJSON(window.siyuan.layout.leftDock),+ right: dockToJSON(window.siyuan.layout.rightDock),+ };+ layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);+ return layoutJSON;+}+const initInternalDock = (dockItem: IDockTab[]) => {dockItem.forEach((existSubItem) => {if (existSubItem.hotkeyLangId) {@@ -537,7 +539,6 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any, breajson.mode = layout.editor.protyle.preview.element.classList.contains("fn__none") ? "wysiwyg" : "preview";json.action = layout.editor.protyle.block.showAll ? Constants.CB_GET_ALL : Constants.CB_GET_SCROLL;json.instance = "Editor";- saveScroll(layout.editor.protyle);} else if (layout instanceof Asset) {json.path = layout.path;if (layout.pdfObject) {diff --git a/app/src/menus/workspace.ts b/app/src/menus/workspace.tsindex fa5a243a5e..ccabd433eb 100644--- a/app/src/menus/workspace.ts+++ b/app/src/menus/workspace.ts@@ -11,7 +11,7 @@ import {isInAndroid, isInIOS, isIPad, setStorageVal, writeText} from "../protyleimport {openCard} from "../card/openCard";import {openSetting} from "../config";import {getAllDocks} from "../layout/getAll";-import {exportLayout} from "../layout/util";+import {exportLayout, getAllLayout} from "../layout/util";import {getDockByType} from "../layout/tabUtil";import {exitSiYuan, lockScreen} from "../dialog/processSystem";import {showMessage} from "../dialog/message";@@ -252,11 +252,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {if (item.name === value) {saveDialog.destroy();confirmDialog(window.siyuan.languages.save, window.siyuan.languages.exportTplTip, () => {- item.layout = exportLayout({- reload: false,- onlyData: true,- errorExit: false,- });+ item.layout = getAllLayout();setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]);});return true;@@ -267,11 +263,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {}window.siyuan.storage[Constants.LOCAL_LAYOUTS].push({name: value,- layout: exportLayout({- reload: false,- onlyData: true,- errorExit: false,- })+ layout: getAllLayout()});setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]);saveDialog.destroy();@@ -427,10 +419,8 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {icon: "iconQuit",click: () => {exportLayout({- reload: false,- onlyData: false,errorExit: true,- cb: exitSiYuan+ cb: exitSiYuan,});}}).element);diff --git a/app/src/mobile/menu/getRecentDocs.ts b/app/src/mobile/menu/getRecentDocs.tsindex 43227044ae..bde4ebb549 100644--- a/app/src/mobile/menu/getRecentDocs.ts+++ b/app/src/mobile/menu/getRecentDocs.ts@@ -24,7 +24,7 @@ ${unicode2Emoji(item.icon || Constants.SIYUAN_IMAGE_FILE, "b3-list-item__graphicelement.firstElementChild.addEventListener("click", (event) => {const liElement = hasClosestByClassName(event.target as HTMLElement, "b3-list-item");if (liElement) {- openMobileFileById(app, liElement.dataset.nodeId, [Constants.CB_GET_SCROLL]);+ openMobileFileById(app, liElement.dataset.nodeId, [Constants.CB_GET_SCROLL, Constants.CB_GET_HL]);}});}diff --git a/app/src/mobile/util/initFramework.ts b/app/src/mobile/util/initFramework.tsindex 6d89555fbf..9c11fb1c31 100644--- a/app/src/mobile/util/initFramework.ts+++ b/app/src/mobile/util/initFramework.ts@@ -180,7 +180,7 @@ export const initFramework = (app: App, isStart: boolean) => {const localDoc = window.siyuan.storage[Constants.LOCAL_DOCINFO];fetchPost("/api/block/checkBlockExist", {id: localDoc.id}, existResponse => {if (existResponse.data) {- openMobileFileById(app, localDoc.id, [Constants.CB_GET_SCROLL]);+ openMobileFileById(app, localDoc.id, [Constants.CB_GET_SCROLL, Constants.CB_GET_HL]);} else {fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => {if (response.data.length !== 0) {diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.tsindex 8da1def18a..3d735c6ace 100644--- a/app/src/protyle/util/onGet.ts+++ b/app/src/protyle/util/onGet.ts@@ -395,7 +395,7 @@ const focusElementById = (protyle: IProtyle, action: string[], scrollAttr?: IScrif (hasScrollTop) {protyle.contentElement.scrollTop = scrollAttr.scrollTop;}- if (action.includes(Constants.CB_GET_FOCUS) || action.includes(Constants.CB_GET_HL) || action.includes(Constants.CB_GET_FOCUSFIRST)) {+ if (action.includes(Constants.CB_GET_FOCUS) || action.includes(Constants.CB_GET_SCROLL) || action.includes(Constants.CB_GET_HL) || action.includes(Constants.CB_GET_FOCUSFIRST)) {const contentRect = protyle.contentElement.getBoundingClientRect();const focusRect = focusElement.getBoundingClientRect();if (!hasScrollTop && (contentRect.top > focusRect.top || contentRect.bottom < focusRect.bottom)) {diff --git a/app/src/util/assets.ts b/app/src/util/assets.tsindex 369530b60f..a250ddeeae 100644--- a/app/src/util/assets.ts+++ b/app/src/util/assets.ts@@ -139,8 +139,9 @@ export const initAssets = () => {if (window.siyuan.config.appearance.themeJS) {/// #if !MOBILEexportLayout({- reload: true,- onlyData: false,+ cb() {+ window.location.reload();+ },errorExit: false,});/// #else@@ -271,8 +272,9 @@ export const setMode = (modeElementValue: number) => {window.siyuan.config.appearance.themeDark !== response.data.themeDark)) {exportLayout({- reload: true,- onlyData: false,+ cb() {+ window.location.reload();+ },errorExit: false,});return;@@ -282,8 +284,9 @@ export const setMode = (modeElementValue: number) => {(response.data.mode === 1 && OSTheme === "light") || (response.data.mode === 0 && OSTheme === "dark"))) {exportLayout({- reload: true,- onlyData: false,+ cb() {+ window.location.reload();+ },errorExit: false,});return;diff --git a/app/src/util/processMessage.ts b/app/src/util/processMessage.tsindex 67c4883172..486ae21b4c 100644--- a/app/src/util/processMessage.ts+++ b/app/src/util/processMessage.ts@@ -24,14 +24,15 @@ export const processMessage = (response: IWebSocketData) => {if ("reloadui" === response.cmd) {if (response.data?.resetScroll) {window.siyuan.storage[Constants.LOCAL_FILEPOSITION] = {};- setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]);+ setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]);}/// #if MOBILEwindow.location.reload();/// #elseexportLayout({- reload: true,- onlyData: false,+ cb() {+ window.location.reload();+ },errorExit: false,});/// #endifdiff --git a/app/src/window/onWindowsMsg.ts b/app/src/window/onWindowsMsg.tsindex d39b67fd05..778becfd2a 100644--- a/app/src/window/onWindowsMsg.ts+++ b/app/src/window/onWindowsMsg.ts@@ -16,8 +16,6 @@ export const onWindowsMsg = (ipcData: IWebSocketData) => {break;case "lockscreen":exportLayout({- reload: false,- onlyData: false,errorExit: false,cb() {fetchPost("/api/system/logoutAuth", {}, () => {@@ -29,8 +27,6 @@ export const onWindowsMsg = (ipcData: IWebSocketData) => {case "lockscreenByMode":if (window.siyuan.config.system.lockScreenMode === 1) {exportLayout({- reload: false,- onlyData: false,errorExit: false,cb() {fetchPost("/api/system/logoutAuth", {}, () => {