Skip to content

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

:bug: Support zooming out to notebook documents https://github.com/siyuan-note/siyuan/issues/18812

Daniel5e3b79632a4a
diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts
index 32d0c0e5ec..d200a86777 100644
--- a/app/src/menus/protyle.ts
+++ b/app/src/menus/protyle.ts
@@ -73,6 +73,7 @@ import {
isDefaultTableColumnWidth,
TABLE_DEFAULT_COLUMN_WIDTH,
} from "../protyle/util/tableColumnWidth";
+import {getParentDocumentID} from "../protyle/util/parentDocument";
const renderAssetList = (element: Element, k: string, position: IPosition, exts: string[] = []) => {
fetchPost("/api/search/searchAsset", {
@@ -940,14 +941,19 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {
export const enterBack = (protyle: IProtyle, id: string) => {
if (!protyle.block.showAll) {
- const ids = protyle.path.split("/");
- if (ids.length > 2) {
+ const parentDocumentID = getParentDocumentID({
+ path: protyle.path,
+ notebookID: protyle.notebookId,
+ rootID: protyle.block.rootID,
+ boxDocEnabled: window.siyuan.config.fileTree.boxDocEnabled,
+ });
+ if (parentDocumentID) {
/// #if MOBILE
- openMobileFileById(protyle.app, ids[ids.length - 2], [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]);
+ openMobileFileById(protyle.app, parentDocumentID, [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]);
/// #else
openFileById({
app: protyle.app,
- id: ids[ids.length - 2],
+ id: parentDocumentID,
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
});
/// #endif
diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts
index d43c7b106d..11bb8d4e48 100644
--- a/app/src/protyle/header/Title.ts
+++ b/app/src/protyle/header/Title.ts
@@ -30,6 +30,7 @@ import {electronUndo} from "../undo";
import {enableLuteMarkdownSyntax, restoreLuteMarkdownSyntax} from "../util/paste";
import {addSpellcheckMenuItems, requestSpellcheckContext} from "../../menus/spellcheck";
import {focusAVByArrow} from "../render/av/focus";
+import {getParentDocumentID} from "../util/parentDocument";
export class Title {
public element: HTMLElement;
@@ -123,12 +124,17 @@ export class Title {
return;
}
if (matchHotKey(window.siyuan.config.keymap.general.enterBack.custom, event)) {
- const ids = protyle.path.split("/");
- if (ids.length > 2) {
+ const parentDocumentID = getParentDocumentID({
+ path: protyle.path,
+ notebookID: protyle.notebookId,
+ rootID: protyle.block.rootID,
+ boxDocEnabled: window.siyuan.config.fileTree.boxDocEnabled,
+ });
+ if (parentDocumentID) {
/// #if !MOBILE
openFileById({
app: protyle.app,
- id: ids[ids.length - 2],
+ id: parentDocumentID,
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
});
/// #endif
diff --git a/app/src/protyle/util/parentDocument.test.ts b/app/src/protyle/util/parentDocument.test.ts
new file mode 100644
index 0000000000..93eeefe361
--- /dev/null
+++ b/app/src/protyle/util/parentDocument.test.ts
@@ -0,0 +1,41 @@
+import {describe, it} from "node:test";
+import * as assert from "node:assert/strict";
+import {getParentDocumentID} from "./parentDocument";
+
+describe("getParentDocumentID", () => {
+ it("returns the physical parent of a nested document", () => {
+ assert.equal(getParentDocumentID({
+ path: "/20260818120000-parent1/20260818120001-parent2/20260818120002-child.sy",
+ notebookID: "20260818120003-notebook",
+ rootID: "20260818120002-child",
+ boxDocEnabled: false,
+ }), "20260818120001-parent2");
+ });
+
+ it("returns the notebook document for a top-level document when enabled", () => {
+ assert.equal(getParentDocumentID({
+ path: "/20260818120002-child.sy",
+ notebookID: "20260818120003-notebook",
+ rootID: "20260818120002-child",
+ boxDocEnabled: true,
+ }), "20260818120003-notebook");
+ });
+
+ it("does not return the notebook document when disabled", () => {
+ assert.equal(getParentDocumentID({
+ path: "/20260818120002-child.sy",
+ notebookID: "20260818120003-notebook",
+ rootID: "20260818120002-child",
+ boxDocEnabled: false,
+ }), undefined);
+ });
+
+ it("does not return a parent for the notebook document itself", () => {
+ assert.equal(getParentDocumentID({
+ path: "/20260818120003-notebook.sy",
+ notebookID: "20260818120003-notebook",
+ rootID: "20260818120003-notebook",
+ boxDocEnabled: true,
+ }), undefined);
+ });
+});
diff --git a/app/src/protyle/util/parentDocument.ts b/app/src/protyle/util/parentDocument.ts
new file mode 100644
index 0000000000..1385ed14ab
--- /dev/null
+++ b/app/src/protyle/util/parentDocument.ts
@@ -0,0 +1,14 @@
+export const getParentDocumentID = (options: {
+ path: string,
+ notebookID: string,
+ rootID: string,
+ boxDocEnabled: boolean,
+}) => {
+ const ids = options.path.split("/");
+ if (ids.length > 2) {
+ return ids[ids.length - 2];
+ }
+ if (options.boxDocEnabled && options.rootID !== options.notebookID) {
+ return options.notebookID;
+ }
+};