Forráskód Böngészése

:recycle: https://github.com/siyuan-note/siyuan/issues/9846

Vanessa 1 éve
szülő
commit
801f665c90

+ 5 - 6
app/src/boot/globalEvent/event.ts

@@ -13,8 +13,7 @@ import {initTabMenu} from "../../menus/tab";
 import {getInstanceById} from "../../layout/util";
 import {getInstanceById} from "../../layout/util";
 import {Tab} from "../../layout/Tab";
 import {Tab} from "../../layout/Tab";
 import {hideTooltip} from "../../dialog/tooltip";
 import {hideTooltip} from "../../dialog/tooltip";
-import {fetchPost} from "../../util/fetch";
-import {openFileById} from "../../editor/util";
+import {checkFold, openFileById} from "../../editor/util";
 
 
 export const initWindowEvent = (app: App) => {
 export const initWindowEvent = (app: App) => {
     document.body.addEventListener("mouseleave", () => {
     document.body.addEventListener("mouseleave", () => {
@@ -131,15 +130,15 @@ export const initWindowEvent = (app: App) => {
             if (backlinkBreadcrumbItemElement) {
             if (backlinkBreadcrumbItemElement) {
                 const breadcrumbId = backlinkBreadcrumbItemElement.getAttribute("data-id") || backlinkBreadcrumbItemElement.getAttribute("data-node-id");
                 const breadcrumbId = backlinkBreadcrumbItemElement.getAttribute("data-id") || backlinkBreadcrumbItemElement.getAttribute("data-node-id");
                 if (breadcrumbId) {
                 if (breadcrumbId) {
-                    fetchPost("/api/block/checkBlockFold", {id: breadcrumbId}, (foldResponse) => {
+                    checkFold(breadcrumbId, (zoomIn) => {
                         openFileById({
                         openFileById({
                             app,
                             app,
                             id: breadcrumbId,
                             id: breadcrumbId,
-                            action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
-                            zoomIn: foldResponse.data
+                            action: zoomIn ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
+                            zoomIn,
                         });
                         });
                         window.siyuan.menus.menu.remove();
                         window.siyuan.menus.menu.remove();
-                    });
+                    })
                 }
                 }
                 event.stopImmediatePropagation();
                 event.stopImmediatePropagation();
                 event.preventDefault();
                 event.preventDefault();

+ 4 - 4
app/src/boot/onGetConfig.ts

@@ -13,7 +13,7 @@ import {appearance} from "../config/appearance";
 import {fetchPost, fetchSyncPost} from "../util/fetch";
 import {fetchPost, fetchSyncPost} from "../util/fetch";
 import {addGA, initAssets, setInlineStyle} from "../util/assets";
 import {addGA, initAssets, setInlineStyle} from "../util/assets";
 import {renderSnippet} from "../config/util/snippets";
 import {renderSnippet} from "../config/util/snippets";
-import {openFile, openFileById} from "../editor/util";
+import {checkFold, openFile, openFileById} from "../editor/util";
 import {focusByRange} from "../protyle/util/selection";
 import {focusByRange} from "../protyle/util/selection";
 import {exitSiYuan} from "../dialog/processSystem";
 import {exitSiYuan} from "../dialog/processSystem";
 import {isWindow} from "../util/functions";
 import {isWindow} from "../util/functions";
@@ -307,12 +307,12 @@ export const initWindow = async (app: App) => {
                 const focus = urlObj.searchParams.get("focus") === "1";
                 const focus = urlObj.searchParams.get("focus") === "1";
                 fetchPost("/api/block/checkBlockExist", {id}, existResponse => {
                 fetchPost("/api/block/checkBlockExist", {id}, existResponse => {
                     if (existResponse.data) {
                     if (existResponse.data) {
-                        fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
+                        checkFold(id, (zoomIn) => {
                             openFileById({
                             openFileById({
                                 app,
                                 app,
                                 id,
                                 id,
-                                action: (foldResponse.data || focus) ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
-                                zoomIn: foldResponse.data || focus
+                                action: (zoomIn || focus) ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
+                                zoomIn: zoomIn || focus
                             });
                             });
                         });
                         });
                         ipcRenderer.send(Constants.SIYUAN_CMD, "show");
                         ipcRenderer.send(Constants.SIYUAN_CMD, "show");

+ 3 - 2
app/src/layout/dock/Bookmark.ts

@@ -9,6 +9,7 @@ import {checkFold, openFileById} from "../../editor/util";
 import {hasClosestByClassName} from "../../protyle/util/hasClosest";
 import {hasClosestByClassName} from "../../protyle/util/hasClosest";
 import {openBookmarkMenu} from "../../menus/bookmark";
 import {openBookmarkMenu} from "../../menus/bookmark";
 import {App} from "../../index";
 import {App} from "../../index";
+import {Constants} from "../../constants";
 
 
 export class Bookmark extends Model {
 export class Bookmark extends Model {
     private openNodes: string[];
     private openNodes: string[];
@@ -98,12 +99,12 @@ export class Bookmark extends Model {
             },
             },
             ctrlClick: (element: HTMLElement) => {
             ctrlClick: (element: HTMLElement) => {
                 const id = element.getAttribute("data-node-id")
                 const id = element.getAttribute("data-node-id")
-                checkFold(id, (zoomIn, action: string[]) => {
+                checkFold(id, (zoomIn) => {
                     openFileById({
                     openFileById({
                         app,
                         app,
                         id,
                         id,
                         keepCursor: true,
                         keepCursor: true,
-                        action,
+                        action: zoomIn ? [Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
                         zoomIn
                         zoomIn
                     });
                     });
                 })
                 })

+ 4 - 4
app/src/layout/dock/Outline.ts

@@ -7,7 +7,7 @@ import {fetchPost} from "../../util/fetch";
 import {getAllModels} from "../getAll";
 import {getAllModels} from "../getAll";
 import {hasClosestBlock, hasClosestByClassName, hasTopClosestByClassName} from "../../protyle/util/hasClosest";
 import {hasClosestBlock, hasClosestByClassName, hasTopClosestByClassName} from "../../protyle/util/hasClosest";
 import {updateHotkeyTip} from "../../protyle/util/compatibility";
 import {updateHotkeyTip} from "../../protyle/util/compatibility";
-import {openFileById} from "../../editor/util";
+import {checkFold, openFileById} from "../../editor/util";
 import {Constants} from "../../constants";
 import {Constants} from "../../constants";
 import {escapeHtml} from "../../util/escape";
 import {escapeHtml} from "../../util/escape";
 import {unicode2Emoji} from "../../emoji";
 import {unicode2Emoji} from "../../emoji";
@@ -123,13 +123,13 @@ export class Outline extends Model {
                         });
                         });
                     }
                     }
                 } else {
                 } else {
-                    fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
+                    checkFold(id, (zoomIn) => {
                         openFileById({
                         openFileById({
                             app: options.app,
                             app: options.app,
                             id,
                             id,
-                            action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_FOCUS, Constants.CB_GET_SETID, Constants.CB_GET_CONTEXT, Constants.CB_GET_HTML],
+                            action: zoomIn ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_FOCUS, Constants.CB_GET_SETID, Constants.CB_GET_CONTEXT, Constants.CB_GET_HTML],
                         });
                         });
-                    });
+                    })
                 }
                 }
             },
             },
             ctrlClick(element: HTMLElement) {
             ctrlClick(element: HTMLElement) {

+ 13 - 13
app/src/menus/protyle.ts

@@ -30,7 +30,7 @@ import {onGet} from "../protyle/util/onGet";
 import {getAllModels} from "../layout/getAll";
 import {getAllModels} from "../layout/getAll";
 import {pasteAsPlainText, pasteEscaped, pasteText} from "../protyle/util/paste";
 import {pasteAsPlainText, pasteEscaped, pasteText} from "../protyle/util/paste";
 /// #if !MOBILE
 /// #if !MOBILE
-import {openFileById, updateBacklinkGraph} from "../editor/util";
+import {checkFold, openFileById, updateBacklinkGraph} from "../editor/util";
 import {openGlobalSearch} from "../search/util";
 import {openGlobalSearch} from "../search/util";
 import {openNewWindowById} from "../window/openNewWindow";
 import {openNewWindowById} from "../window/openNewWindow";
 /// #endif
 /// #endif
@@ -351,12 +351,12 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
         icon: "iconOpen",
         icon: "iconOpen",
         accelerator: window.siyuan.config.keymap.editor.general.openBy.custom + "/Click",
         accelerator: window.siyuan.config.keymap.editor.general.openBy.custom + "/Click",
         click() {
         click() {
-            fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
+            checkFold(refBlockId, (zoomIn, action) => {
                 openFileById({
                 openFileById({
                     app: protyle.app,
                     app: protyle.app,
                     id: refBlockId,
                     id: refBlockId,
-                    action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
-                    zoomIn: foldResponse.data
+                    action,
+                    zoomIn
                 });
                 });
             });
             });
         }
         }
@@ -366,13 +366,13 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
         icon: "iconEyeoff",
         icon: "iconEyeoff",
         accelerator: window.siyuan.config.keymap.editor.general.refTab.custom + "/⌘Click",
         accelerator: window.siyuan.config.keymap.editor.general.refTab.custom + "/⌘Click",
         click() {
         click() {
-            fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
+            checkFold(refBlockId, (zoomIn) => {
                 openFileById({
                 openFileById({
                     app: protyle.app,
                     app: protyle.app,
                     id: refBlockId,
                     id: refBlockId,
-                    action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
+                    action: zoomIn ? [Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
                     keepCursor: true,
                     keepCursor: true,
-                    zoomIn: foldResponse.data
+                    zoomIn
                 });
                 });
             });
             });
         }
         }
@@ -382,13 +382,13 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
         icon: "iconLayoutRight",
         icon: "iconLayoutRight",
         accelerator: window.siyuan.config.keymap.editor.general.insertRight.custom + "/⌥Click",
         accelerator: window.siyuan.config.keymap.editor.general.insertRight.custom + "/⌥Click",
         click() {
         click() {
-            fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
+            checkFold(refBlockId, (zoomIn, action) => {
                 openFileById({
                 openFileById({
                     app: protyle.app,
                     app: protyle.app,
                     id: refBlockId,
                     id: refBlockId,
                     position: "right",
                     position: "right",
-                    action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
-                    zoomIn: foldResponse.data
+                    action,
+                    zoomIn
                 });
                 });
             });
             });
         }
         }
@@ -398,13 +398,13 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
         icon: "iconLayoutBottom",
         icon: "iconLayoutBottom",
         accelerator: window.siyuan.config.keymap.editor.general.insertBottom.custom + (window.siyuan.config.keymap.editor.general.insertBottom.custom ? "/" : "") + "⇧Click",
         accelerator: window.siyuan.config.keymap.editor.general.insertBottom.custom + (window.siyuan.config.keymap.editor.general.insertBottom.custom ? "/" : "") + "⇧Click",
         click() {
         click() {
-            fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
+            checkFold(refBlockId, (zoomIn, action) => {
                 openFileById({
                 openFileById({
                     app: protyle.app,
                     app: protyle.app,
                     id: refBlockId,
                     id: refBlockId,
                     position: "bottom",
                     position: "bottom",
-                    action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
-                    zoomIn: foldResponse.data
+                    action,
+                    zoomIn
                 });
                 });
             });
             });
         }
         }

+ 20 - 15
app/src/menus/util.ts

@@ -4,7 +4,7 @@ import * as path from "path";
 /// #endif
 /// #endif
 import {fetchPost} from "../util/fetch";
 import {fetchPost} from "../util/fetch";
 import {getAssetName, pathPosix, showFileInFolder} from "../util/pathName";
 import {getAssetName, pathPosix, showFileInFolder} from "../util/pathName";
-import {openFileById} from "../editor/util";
+import {checkFold, openFileById} from "../editor/util";
 import {Constants} from "../constants";
 import {Constants} from "../constants";
 import {openNewWindowById} from "../window/openNewWindow";
 import {openNewWindowById} from "../window/openNewWindow";
 import {MenuItem} from "./Menu";
 import {MenuItem} from "./Menu";
@@ -17,7 +17,7 @@ export const exportAsset = (src: string) => {
         label: window.siyuan.languages.export,
         label: window.siyuan.languages.export,
         icon: "iconUpload",
         icon: "iconUpload",
         async click() {
         async click() {
-            const result = await ipcRenderer.invoke(Constants.SIYUAN_GET,{
+            const result = await ipcRenderer.invoke(Constants.SIYUAN_GET, {
                 cmd: "showSaveDialog",
                 cmd: "showSaveDialog",
                 defaultPath: getAssetName(src) + pathPosix().extname(src),
                 defaultPath: getAssetName(src) + pathPosix().extname(src),
                 properties: ["showOverwriteConfirmation"],
                 properties: ["showOverwriteConfirmation"],
@@ -41,15 +41,15 @@ export const openEditorTab = (app: App, id: string, notebookId?: string, pathStr
             if (notebookId) {
             if (notebookId) {
                 openFileById({app, id, position: "right", action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]});
                 openFileById({app, id, position: "right", action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]});
             } else {
             } else {
-                fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
+                checkFold(id, (zoomIn, action) => {
                     openFileById({
                     openFileById({
                         app,
                         app,
                         id,
                         id,
                         position: "right",
                         position: "right",
-                        action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
-                        zoomIn: foldResponse.data
+                        action,
+                        zoomIn
                     });
                     });
-                });
+                })
             }
             }
         }
         }
     }, {
     }, {
@@ -60,15 +60,15 @@ export const openEditorTab = (app: App, id: string, notebookId?: string, pathStr
             if (notebookId) {
             if (notebookId) {
                 openFileById({app, id, position: "bottom", action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]});
                 openFileById({app, id, position: "bottom", action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]});
             } else {
             } else {
-                fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
+                checkFold(id, (zoomIn, action)=> {
                     openFileById({
                     openFileById({
                         app,
                         app,
                         id,
                         id,
                         position: "bottom",
                         position: "bottom",
-                        action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
-                        zoomIn: foldResponse.data
+                        action,
+                        zoomIn
                     });
                     });
-                });
+                })
             }
             }
         }
         }
     }];
     }];
@@ -78,17 +78,22 @@ export const openEditorTab = (app: App, id: string, notebookId?: string, pathStr
             accelerator: "⌥⌘Click",
             accelerator: "⌥⌘Click",
             click: () => {
             click: () => {
                 if (notebookId) {
                 if (notebookId) {
-                    openFileById({app, id, action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL], removeCurrentTab: false});
+                    openFileById({
+                        app,
+                        id,
+                        action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL],
+                        removeCurrentTab: false
+                    });
                 } else {
                 } else {
-                    fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
+                    checkFold(id, (zoomIn, action)=> {
                         openFileById({
                         openFileById({
                             app,
                             app,
                             id,
                             id,
-                            action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
-                            zoomIn: foldResponse.data,
+                            action,
+                            zoomIn,
                             removeCurrentTab: false
                             removeCurrentTab: false
                         });
                         });
-                    });
+                    })
                 }
                 }
             }
             }
         });
         });

+ 3 - 2
app/src/mobile/dock/MobileBookmarks.ts

@@ -5,6 +5,7 @@ import {hasClosestByClassName} from "../../protyle/util/hasClosest";
 import {openMobileFileById} from "../editor";
 import {openMobileFileById} from "../editor";
 import {openBookmarkMenu} from "../../menus/bookmark";
 import {openBookmarkMenu} from "../../menus/bookmark";
 import {App} from "../../index";
 import {App} from "../../index";
+import {checkFold, openFileById} from "../../editor/util";
 
 
 export class MobileBookmarks {
 export class MobileBookmarks {
     public element: HTMLElement;
     public element: HTMLElement;
@@ -38,8 +39,8 @@ export class MobileBookmarks {
                         return;
                         return;
                     }
                     }
                 }
                 }
-                fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
-                    openMobileFileById(app, id, foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
+                checkFold(id, (zoomIn, action) => {
+                    openMobileFileById(app, id, zoomIn ? [Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
                 });
                 });
             },
             },
             blockExtHTML: '<span class="b3-list-item__action"><svg><use xlink:href="#iconMore"></use></svg></span>',
             blockExtHTML: '<span class="b3-list-item__action"><svg><use xlink:href="#iconMore"></use></svg></span>',

+ 3 - 2
app/src/mobile/dock/MobileOutline.ts

@@ -5,6 +5,7 @@ import {Constants} from "../../constants";
 import {getEventName} from "../../protyle/util/compatibility";
 import {getEventName} from "../../protyle/util/compatibility";
 import {App} from "../../index";
 import {App} from "../../index";
 import {closePanel} from "../util/closePanel";
 import {closePanel} from "../util/closePanel";
+import {checkFold} from "../../editor/util";
 
 
 export class MobileOutline {
 export class MobileOutline {
     private tree: Tree;
     private tree: Tree;
@@ -33,8 +34,8 @@ export class MobileOutline {
                     closePanel();
                     closePanel();
                     document.getElementById(id)?.scrollIntoView();
                     document.getElementById(id)?.scrollIntoView();
                 } else {
                 } else {
-                    fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
-                        openMobileFileById(app, id, foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_FOCUS, Constants.CB_GET_SETID, Constants.CB_GET_CONTEXT, Constants.CB_GET_HTML]);
+                    checkFold(id, (zoomIn) => {
+                        openMobileFileById(app, id, zoomIn ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_FOCUS, Constants.CB_GET_SETID, Constants.CB_GET_CONTEXT, Constants.CB_GET_HTML]);
                     });
                     });
                 }
                 }
             }
             }

+ 4 - 3
app/src/mobile/menu/search.ts

@@ -24,6 +24,7 @@ import {
     renderPreview,
     renderPreview,
 } from "../../search/assets";
 } from "../../search/assets";
 import {addClearButton} from "../../util/addClearButton";
 import {addClearButton} from "../../util/addClearButton";
+import {checkFold} from "../../editor/util";
 
 
 const replace = (element: Element, config: ISearchOption, isAll: boolean) => {
 const replace = (element: Element, config: ISearchOption, isAll: boolean) => {
     if (config.method === 1 || config.method === 2) {
     if (config.method === 1 || config.method === 2) {
@@ -573,8 +574,8 @@ const initSearchEvent = (app: App, element: Element, config: ISearchOption) => {
                         if (window.siyuan.mobile.editor.protyle) {
                         if (window.siyuan.mobile.editor.protyle) {
                             preventScroll(window.siyuan.mobile.editor.protyle);
                             preventScroll(window.siyuan.mobile.editor.protyle);
                         }
                         }
-                        fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
-                            openMobileFileById(app, id, foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
+                        checkFold(id, (zoomIn) => {
+                            openMobileFileById(app, id, zoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
                         });
                         });
                         closePanel();
                         closePanel();
                     } else {
                     } else {
@@ -717,7 +718,7 @@ const goAsset = () => {
     assetInputEvent(assetsElement, localSearch);
     assetInputEvent(assetsElement, localSearch);
     addClearButton({
     addClearButton({
         inputElement,
         inputElement,
-        className:"toolbar__icon",
+        className: "toolbar__icon",
         clearCB() {
         clearCB() {
             assetInputEvent(assetsElement, localSearch);
             assetInputEvent(assetsElement, localSearch);
         }
         }

+ 24 - 25
app/src/protyle/wysiwyg/index.ts

@@ -58,7 +58,7 @@ import {blockRender} from "../render/blockRender";
 /// #if !MOBILE
 /// #if !MOBILE
 import {getAllModels} from "../../layout/getAll";
 import {getAllModels} from "../../layout/getAll";
 import {pushBack} from "../../util/backForward";
 import {pushBack} from "../../util/backForward";
-import {openAsset, openBy, openFileById} from "../../editor/util";
+import {checkFold, openAsset, openBy, openFileById} from "../../editor/util";
 import {openGlobalSearch} from "../../search/util";
 import {openGlobalSearch} from "../../search/util";
 /// #else
 /// #else
 import {popSearch} from "../../mobile/menu/search";
 import {popSearch} from "../../mobile/menu/search";
@@ -1691,12 +1691,12 @@ export class WYSIWYG {
                 const breadcrumbId = backlinkBreadcrumbItemElement.getAttribute("data-id");
                 const breadcrumbId = backlinkBreadcrumbItemElement.getAttribute("data-id");
                 if (breadcrumbId) {
                 if (breadcrumbId) {
                     if (ctrlIsPressed) {
                     if (ctrlIsPressed) {
-                        fetchPost("/api/block/checkBlockFold", {id: breadcrumbId}, (foldResponse) => {
+                        checkFold(breadcrumbId, (zoomIn) => {
                             openFileById({
                             openFileById({
                                 app: protyle.app,
                                 app: protyle.app,
                                 id: breadcrumbId,
                                 id: breadcrumbId,
-                                action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
-                                zoomIn: foldResponse.data
+                                action: zoomIn ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
+                                zoomIn
                             });
                             });
                         });
                         });
                     } else {
                     } else {
@@ -1754,10 +1754,9 @@ export class WYSIWYG {
                 } else if (aElement) {
                 } else if (aElement) {
                     refBlockId = aLink.substring(16, 38);
                     refBlockId = aLink.substring(16, 38);
                 }
                 }
-
-                fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
+                checkFold(refBlockId, (zoomIn, action) => {
                     /// #if MOBILE
                     /// #if MOBILE
-                    openMobileFileById(protyle.app, refBlockId, foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
+                    openMobileFileById(protyle.app, refBlockId, zoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
                     activeBlur();
                     activeBlur();
                     hideKeyboardToolbar();
                     hideKeyboardToolbar();
                     /// #else
                     /// #else
@@ -1766,35 +1765,35 @@ export class WYSIWYG {
                             app: protyle.app,
                             app: protyle.app,
                             id: refBlockId,
                             id: refBlockId,
                             position: "bottom",
                             position: "bottom",
-                            action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
-                            zoomIn: foldResponse.data
+                            action,
+                            zoomIn
                         });
                         });
                     } else if (event.altKey) {
                     } else if (event.altKey) {
                         openFileById({
                         openFileById({
                             app: protyle.app,
                             app: protyle.app,
                             id: refBlockId,
                             id: refBlockId,
                             position: "right",
                             position: "right",
-                            action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
-                            zoomIn: foldResponse.data
+                            action,
+                            zoomIn
                         });
                         });
                     } else if (ctrlIsPressed) {
                     } else if (ctrlIsPressed) {
                         openFileById({
                         openFileById({
                             app: protyle.app,
                             app: protyle.app,
                             id: refBlockId,
                             id: refBlockId,
-                            action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
                             keepCursor: true,
                             keepCursor: true,
-                            zoomIn: foldResponse.data
+                            action: zoomIn ? [Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
+                            zoomIn
                         });
                         });
                     } else {
                     } else {
                         openFileById({
                         openFileById({
                             app: protyle.app,
                             app: protyle.app,
                             id: refBlockId,
                             id: refBlockId,
-                            action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
-                            zoomIn: foldResponse.data
+                            action,
+                            zoomIn
                         });
                         });
                     }
                     }
                     /// #endif
                     /// #endif
-                });
+                })
                 /// #if !MOBILE
                 /// #if !MOBILE
                 if (protyle.model) {
                 if (protyle.model) {
                     // 打开双链需记录到后退中 https://github.com/siyuan-note/insider/issues/801
                     // 打开双链需记录到后退中 https://github.com/siyuan-note/insider/issues/801
@@ -1903,9 +1902,9 @@ export class WYSIWYG {
             const embedItemElement = hasClosestByClassName(event.target, "protyle-wysiwyg__embed");
             const embedItemElement = hasClosestByClassName(event.target, "protyle-wysiwyg__embed");
             if (embedItemElement) {
             if (embedItemElement) {
                 const embedId = embedItemElement.getAttribute("data-id");
                 const embedId = embedItemElement.getAttribute("data-id");
-                fetchPost("/api/block/checkBlockFold", {id: embedId}, (foldResponse) => {
+                checkFold(embedId, (zoomIn, action) => {
                     /// #if MOBILE
                     /// #if MOBILE
-                    openMobileFileById(protyle.app, embedId, foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
+                    openMobileFileById(protyle.app, embedId, zoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);
                     activeBlur();
                     activeBlur();
                     hideKeyboardToolbar();
                     hideKeyboardToolbar();
                     /// #else
                     /// #else
@@ -1914,23 +1913,23 @@ export class WYSIWYG {
                             app: protyle.app,
                             app: protyle.app,
                             id: embedId,
                             id: embedId,
                             position: "bottom",
                             position: "bottom",
-                            action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
-                            zoomIn: foldResponse.data
+                            action,
+                            zoomIn
                         });
                         });
                     } else if (event.altKey) {
                     } else if (event.altKey) {
                         openFileById({
                         openFileById({
                             app: protyle.app,
                             app: protyle.app,
                             id: embedId,
                             id: embedId,
                             position: "right",
                             position: "right",
-                            action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
-                            zoomIn: foldResponse.data
+                            action,
+                            zoomIn
                         });
                         });
                     } else if (ctrlIsPressed) {
                     } else if (ctrlIsPressed) {
                         openFileById({
                         openFileById({
                             app: protyle.app,
                             app: protyle.app,
                             id: embedId,
                             id: embedId,
-                            action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
-                            zoomIn: foldResponse.data,
+                            action: zoomIn ? [Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
+                            zoomIn,
                             keepCursor: true,
                             keepCursor: true,
                         });
                         });
                     } else if (!protyle.disabled) {
                     } else if (!protyle.disabled) {
@@ -1942,7 +1941,7 @@ export class WYSIWYG {
                         }));
                         }));
                     }
                     }
                     /// #endif
                     /// #endif
-                });
+                })
                 event.stopPropagation();
                 event.stopPropagation();
                 return;
                 return;
             }
             }

+ 14 - 14
app/src/protyle/wysiwyg/keydown.ts

@@ -39,7 +39,7 @@ import {newFileContentBySelect, rename, replaceFileName} from "../../editor/rena
 import {insertEmptyBlock, jumpToParentNext} from "../../block/util";
 import {insertEmptyBlock, jumpToParentNext} from "../../block/util";
 import {isLocalPath, pathPosix} from "../../util/pathName";
 import {isLocalPath, pathPosix} from "../../util/pathName";
 /// #if !MOBILE
 /// #if !MOBILE
-import {openBy, openFileById} from "../../editor/util";
+import {checkFold, openBy, openFileById} from "../../editor/util";
 /// #endif
 /// #endif
 import {
 import {
     alignImgCenter, alignImgLeft,
     alignImgCenter, alignImgLeft,
@@ -1525,52 +1525,52 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
         if (refElement) {
         if (refElement) {
             const id = refElement.getAttribute("data-id");
             const id = refElement.getAttribute("data-id");
             if (matchHotKey(window.siyuan.config.keymap.editor.general.openBy.custom, event)) {
             if (matchHotKey(window.siyuan.config.keymap.editor.general.openBy.custom, event)) {
-                fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
+                checkFold(id, (zoomIn, action) => {
                     openFileById({
                     openFileById({
                         app: protyle.app,
                         app: protyle.app,
                         id,
                         id,
-                        action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
-                        zoomIn: foldResponse.data
+                        action,
+                        zoomIn
                     });
                     });
-                });
+                })
                 event.preventDefault();
                 event.preventDefault();
                 event.stopPropagation();
                 event.stopPropagation();
                 return true;
                 return true;
             } else if (matchHotKey(window.siyuan.config.keymap.editor.general.refTab.custom, event)) {
             } else if (matchHotKey(window.siyuan.config.keymap.editor.general.refTab.custom, event)) {
                 // 打开块引和编辑器中引用、反链、书签中点击事件需保持一致,都加载上下文
                 // 打开块引和编辑器中引用、反链、书签中点击事件需保持一致,都加载上下文
-                fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
+                checkFold(id, (zoomIn) => {
                     openFileById({
                     openFileById({
                         app: protyle.app,
                         app: protyle.app,
                         id,
                         id,
-                        action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
+                        action: zoomIn ? [Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
                         keepCursor: true,
                         keepCursor: true,
-                        zoomIn: foldResponse.data
+                        zoomIn
                     });
                     });
                 });
                 });
                 event.preventDefault();
                 event.preventDefault();
                 event.stopPropagation();
                 event.stopPropagation();
                 return true;
                 return true;
             } else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertRight.custom, event)) {
             } else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertRight.custom, event)) {
-                fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
+                checkFold(id, (zoomIn, action) => {
                     openFileById({
                     openFileById({
                         app: protyle.app,
                         app: protyle.app,
                         id,
                         id,
                         position: "right",
                         position: "right",
-                        action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
-                        zoomIn: foldResponse.data
+                        action,
+                        zoomIn
                     });
                     });
                 });
                 });
                 event.preventDefault();
                 event.preventDefault();
                 event.stopPropagation();
                 event.stopPropagation();
                 return true;
                 return true;
             } else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertBottom.custom, event)) {
             } else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertBottom.custom, event)) {
-                fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
+                checkFold(id, (zoomIn, action) => {
                     openFileById({
                     openFileById({
                         app: protyle.app,
                         app: protyle.app,
                         id,
                         id,
                         position: "bottom",
                         position: "bottom",
-                        action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
-                        zoomIn: foldResponse.data
+                        action,
+                        zoomIn
                     });
                     });
                 });
                 });
                 event.preventDefault();
                 event.preventDefault();

+ 5 - 5
app/src/search/util.ts

@@ -1081,7 +1081,7 @@ export const getArticle = (options: {
     edit: Protyle
     edit: Protyle
     value: string,
     value: string,
 }) => {
 }) => {
-    fetchPost("/api/block/checkBlockFold", {id: options.id}, (foldResponse) => {
+    checkFold(options.id, (zoomIn) => {
         options.edit.protyle.scroll.lastScrollTop = 0;
         options.edit.protyle.scroll.lastScrollTop = 0;
         addLoading(options.edit.protyle);
         addLoading(options.edit.protyle);
         fetchPost("/api/filetree/getDoc", {
         fetchPost("/api/filetree/getDoc", {
@@ -1089,14 +1089,14 @@ export const getArticle = (options: {
             query: options.value,
             query: options.value,
             queryMethod: options.config.method,
             queryMethod: options.config.method,
             queryTypes: options.config.types,
             queryTypes: options.config.types,
-            mode: foldResponse.data ? 0 : 3,
-            size: foldResponse.data ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
-            zoom: foldResponse.data,
+            mode: zoomIn ? 0 : 3,
+            size: zoomIn ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
+            zoom: zoomIn,
         }, getResponse => {
         }, getResponse => {
             onGet({
             onGet({
                 data: getResponse,
                 data: getResponse,
                 protyle: options.edit.protyle,
                 protyle: options.edit.protyle,
-                action: foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_HL, Constants.CB_GET_HTML],
+                action: zoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_HL, Constants.CB_GET_HTML],
             });
             });
             const matchElement = options.edit.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type~="search-mark"]`);
             const matchElement = options.edit.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type~="search-mark"]`);
             if (matchElement) {
             if (matchElement) {