Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: fix https://github.com/siyuan-note/siyuan/issues/5740

Vanessa87f681cce250
diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts
index c0024adbb7..c5f7335d62 100644
--- a/app/src/editor/util.ts
+++ b/app/src/editor/util.ts
@@ -2,7 +2,7 @@ import {Tab} from "../layout/Tab";
import {Editor} from "./index";
import {Wnd} from "../layout/Wnd";
import {getDockByType, getInstanceById, getWndByLayout} from "../layout/util";
-import {getAllModels} from "../layout/getAll";
+import {getAllModels, getAllTabs} from "../layout/getAll";
import {highlightById, scrollCenter} from "../util/highlightById";
import {getDisplayName, pathPosix} from "../util/pathName";
import {Constants} from "../constants";
@@ -96,6 +96,29 @@ const openFile = (options: IOpenFileOptions) => {
switchEditor(editor, options, allModels);
return true;
}
+ // 没有初始化的页签无法检测到
+ const hasEditor = getAllTabs().find(item => {
+ const initData = item.headElement.getAttribute("data-initdata");
+ if (initData) {
+ const initObj = JSON.parse(initData);
+ if (initObj.rootID === options.rootID || initObj.blockId === options.rootID) {
+ initObj.blockId = options.id
+ initObj.mode = options.mode
+ if (options.zoomIn) {
+ initObj.action = [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS]
+ } else {
+ initObj.action = options.action
+ }
+ delete initObj.scrollAttr
+ item.headElement.setAttribute("data-initdata", JSON.stringify(initObj));
+ item.parent.switchTab(item.headElement);
+ return true;
+ }
+ }
+ });
+ if (hasEditor) {
+ return;
+ }
}
let wnd: Wnd = undefined;
diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts
index 1f71571bb8..0798494eef 100644
--- a/app/src/layout/Wnd.ts
+++ b/app/src/layout/Wnd.ts
@@ -318,7 +318,7 @@ export class Wnd {
tab: currentTab,
blockId: json.blockId,
mode: json.mode,
- action: [json.action],
+ action: typeof json.action === "string" ? [json.action] : json.action,
scrollAttr: json.scrollAttr,
}));
currentTab.headElement.removeAttribute("data-initdata");
diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts
index 4bd72cbe39..355115591f 100644
--- a/app/src/layout/util.ts
+++ b/app/src/layout/util.ts
@@ -322,6 +322,7 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any) => {
json.instance = "Tab";
} else if (layout instanceof Editor) {
json.blockId = layout.editor.protyle.block.id;
+ json.rootID = layout.editor.protyle.block.rootID;
json.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";