diff --git a/app/src/boot/globalEvent/event.ts b/app/src/boot/globalEvent/event.ts index 93c77b246a6..6b228ea4696 100644 --- a/app/src/boot/globalEvent/event.ts +++ b/app/src/boot/globalEvent/event.ts @@ -13,8 +13,7 @@ import {initTabMenu} from "../../menus/tab"; import {getInstanceById} from "../../layout/util"; import {Tab} from "../../layout/Tab"; 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) => { document.body.addEventListener("mouseleave", () => { @@ -131,15 +130,15 @@ export const initWindowEvent = (app: App) => { if (backlinkBreadcrumbItemElement) { const breadcrumbId = backlinkBreadcrumbItemElement.getAttribute("data-id") || backlinkBreadcrumbItemElement.getAttribute("data-node-id"); if (breadcrumbId) { - fetchPost("/api/block/checkBlockFold", {id: breadcrumbId}, (foldResponse) => { + checkFold(breadcrumbId, (zoomIn) => { openFileById({ app, 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(); - }); + }) } event.stopImmediatePropagation(); event.preventDefault(); diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.ts index 7016ec6bcd5..9f726c631be 100644 --- a/app/src/boot/onGetConfig.ts +++ b/app/src/boot/onGetConfig.ts @@ -13,7 +13,7 @@ import {appearance} from "../config/appearance"; import {fetchPost, fetchSyncPost} from "../util/fetch"; import {addGA, initAssets, setInlineStyle} from "../util/assets"; 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 {exitSiYuan} from "../dialog/processSystem"; import {isWindow} from "../util/functions"; @@ -307,12 +307,12 @@ export const initWindow = async (app: App) => { const focus = urlObj.searchParams.get("focus") === "1"; fetchPost("/api/block/checkBlockExist", {id}, existResponse => { if (existResponse.data) { - fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { + checkFold(id, (zoomIn) => { openFileById({ app, 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"); diff --git a/app/src/layout/dock/Bookmark.ts b/app/src/layout/dock/Bookmark.ts index 964289baab2..5a03cd99ddc 100644 --- a/app/src/layout/dock/Bookmark.ts +++ b/app/src/layout/dock/Bookmark.ts @@ -9,6 +9,7 @@ import {checkFold, openFileById} from "../../editor/util"; import {hasClosestByClassName} from "../../protyle/util/hasClosest"; import {openBookmarkMenu} from "../../menus/bookmark"; import {App} from "../../index"; +import {Constants} from "../../constants"; export class Bookmark extends Model { private openNodes: string[]; @@ -98,12 +99,12 @@ export class Bookmark extends Model { }, ctrlClick: (element: HTMLElement) => { const id = element.getAttribute("data-node-id") - checkFold(id, (zoomIn, action: string[]) => { + checkFold(id, (zoomIn) => { openFileById({ app, id, 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 }); }) diff --git a/app/src/layout/dock/Outline.ts b/app/src/layout/dock/Outline.ts index f508d9c6977..07dcf7db61a 100644 --- a/app/src/layout/dock/Outline.ts +++ b/app/src/layout/dock/Outline.ts @@ -7,7 +7,7 @@ import {fetchPost} from "../../util/fetch"; import {getAllModels} from "../getAll"; import {hasClosestBlock, hasClosestByClassName, hasTopClosestByClassName} from "../../protyle/util/hasClosest"; import {updateHotkeyTip} from "../../protyle/util/compatibility"; -import {openFileById} from "../../editor/util"; +import {checkFold, openFileById} from "../../editor/util"; import {Constants} from "../../constants"; import {escapeHtml} from "../../util/escape"; import {unicode2Emoji} from "../../emoji"; @@ -123,13 +123,13 @@ export class Outline extends Model { }); } } else { - fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { + checkFold(id, (zoomIn) => { openFileById({ app: options.app, 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) { diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index bbc5d1d6be6..146d259e496 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -30,7 +30,7 @@ import {onGet} from "../protyle/util/onGet"; import {getAllModels} from "../layout/getAll"; import {pasteAsPlainText, pasteEscaped, pasteText} from "../protyle/util/paste"; /// #if !MOBILE -import {openFileById, updateBacklinkGraph} from "../editor/util"; +import {checkFold, openFileById, updateBacklinkGraph} from "../editor/util"; import {openGlobalSearch} from "../search/util"; import {openNewWindowById} from "../window/openNewWindow"; /// #endif @@ -351,12 +351,12 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => { icon: "iconOpen", accelerator: window.siyuan.config.keymap.editor.general.openBy.custom + "/Click", click() { - fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => { + checkFold(refBlockId, (zoomIn, action) => { openFileById({ app: protyle.app, 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", accelerator: window.siyuan.config.keymap.editor.general.refTab.custom + "/⌘Click", click() { - fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => { + checkFold(refBlockId, (zoomIn) => { openFileById({ app: protyle.app, 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, - zoomIn: foldResponse.data + zoomIn }); }); } @@ -382,13 +382,13 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => { icon: "iconLayoutRight", accelerator: window.siyuan.config.keymap.editor.general.insertRight.custom + "/⌥Click", click() { - fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => { + checkFold(refBlockId, (zoomIn, action) => { openFileById({ app: protyle.app, id: refBlockId, 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", accelerator: window.siyuan.config.keymap.editor.general.insertBottom.custom + (window.siyuan.config.keymap.editor.general.insertBottom.custom ? "/" : "") + "⇧Click", click() { - fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => { + checkFold(refBlockId, (zoomIn, action) => { openFileById({ app: protyle.app, id: refBlockId, 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 }); }); } diff --git a/app/src/menus/util.ts b/app/src/menus/util.ts index 5f6a2eeeac4..176372c51fd 100644 --- a/app/src/menus/util.ts +++ b/app/src/menus/util.ts @@ -4,7 +4,7 @@ import * as path from "path"; /// #endif import {fetchPost} from "../util/fetch"; import {getAssetName, pathPosix, showFileInFolder} from "../util/pathName"; -import {openFileById} from "../editor/util"; +import {checkFold, openFileById} from "../editor/util"; import {Constants} from "../constants"; import {openNewWindowById} from "../window/openNewWindow"; import {MenuItem} from "./Menu"; @@ -17,7 +17,7 @@ export const exportAsset = (src: string) => { label: window.siyuan.languages.export, icon: "iconUpload", async click() { - const result = await ipcRenderer.invoke(Constants.SIYUAN_GET,{ + const result = await ipcRenderer.invoke(Constants.SIYUAN_GET, { cmd: "showSaveDialog", defaultPath: getAssetName(src) + pathPosix().extname(src), properties: ["showOverwriteConfirmation"], @@ -41,15 +41,15 @@ export const openEditorTab = (app: App, id: string, notebookId?: string, pathStr if (notebookId) { openFileById({app, id, position: "right", action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]}); } else { - fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { + checkFold(id, (zoomIn, action) => { openFileById({ app, id, 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) { openFileById({app, id, position: "bottom", action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]}); } else { - fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { + checkFold(id, (zoomIn, action)=> { openFileById({ app, id, 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", click: () => { 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 { - fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { + checkFold(id, (zoomIn, action)=> { openFileById({ app, 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 }); - }); + }) } } }); diff --git a/app/src/mobile/dock/MobileBookmarks.ts b/app/src/mobile/dock/MobileBookmarks.ts index f95eb0356f2..a92a5203b0a 100644 --- a/app/src/mobile/dock/MobileBookmarks.ts +++ b/app/src/mobile/dock/MobileBookmarks.ts @@ -5,6 +5,7 @@ import {hasClosestByClassName} from "../../protyle/util/hasClosest"; import {openMobileFileById} from "../editor"; import {openBookmarkMenu} from "../../menus/bookmark"; import {App} from "../../index"; +import {checkFold, openFileById} from "../../editor/util"; export class MobileBookmarks { public element: HTMLElement; @@ -38,8 +39,8 @@ export class MobileBookmarks { 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: '', diff --git a/app/src/mobile/dock/MobileOutline.ts b/app/src/mobile/dock/MobileOutline.ts index f1d30332a77..f3ef8052504 100644 --- a/app/src/mobile/dock/MobileOutline.ts +++ b/app/src/mobile/dock/MobileOutline.ts @@ -5,6 +5,7 @@ import {Constants} from "../../constants"; import {getEventName} from "../../protyle/util/compatibility"; import {App} from "../../index"; import {closePanel} from "../util/closePanel"; +import {checkFold} from "../../editor/util"; export class MobileOutline { private tree: Tree; @@ -33,8 +34,8 @@ export class MobileOutline { closePanel(); document.getElementById(id)?.scrollIntoView(); } 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]); }); } } diff --git a/app/src/mobile/menu/search.ts b/app/src/mobile/menu/search.ts index 9ced5ca7c48..5f0c9159510 100644 --- a/app/src/mobile/menu/search.ts +++ b/app/src/mobile/menu/search.ts @@ -24,6 +24,7 @@ import { renderPreview, } from "../../search/assets"; import {addClearButton} from "../../util/addClearButton"; +import {checkFold} from "../../editor/util"; const replace = (element: Element, config: ISearchOption, isAll: boolean) => { 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) { 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(); } else { @@ -717,7 +718,7 @@ const goAsset = () => { assetInputEvent(assetsElement, localSearch); addClearButton({ inputElement, - className:"toolbar__icon", + className: "toolbar__icon", clearCB() { assetInputEvent(assetsElement, localSearch); } diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index 1887d610d5b..97a2efcd6b5 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -58,7 +58,7 @@ import {blockRender} from "../render/blockRender"; /// #if !MOBILE import {getAllModels} from "../../layout/getAll"; 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"; /// #else import {popSearch} from "../../mobile/menu/search"; @@ -1691,12 +1691,12 @@ export class WYSIWYG { const breadcrumbId = backlinkBreadcrumbItemElement.getAttribute("data-id"); if (breadcrumbId) { if (ctrlIsPressed) { - fetchPost("/api/block/checkBlockFold", {id: breadcrumbId}, (foldResponse) => { + checkFold(breadcrumbId, (zoomIn) => { openFileById({ app: protyle.app, 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 { @@ -1754,10 +1754,9 @@ export class WYSIWYG { } else if (aElement) { refBlockId = aLink.substring(16, 38); } - - fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => { + checkFold(refBlockId, (zoomIn, action) => { /// #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(); hideKeyboardToolbar(); /// #else @@ -1766,35 +1765,35 @@ export class WYSIWYG { app: protyle.app, id: refBlockId, 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) { openFileById({ app: protyle.app, id: refBlockId, 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) { openFileById({ app: protyle.app, 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, - 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 { openFileById({ app: protyle.app, 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 - }); + }) /// #if !MOBILE if (protyle.model) { // 打开双链需记录到后退中 https://github.com/siyuan-note/insider/issues/801 @@ -1903,9 +1902,9 @@ export class WYSIWYG { const embedItemElement = hasClosestByClassName(event.target, "protyle-wysiwyg__embed"); if (embedItemElement) { const embedId = embedItemElement.getAttribute("data-id"); - fetchPost("/api/block/checkBlockFold", {id: embedId}, (foldResponse) => { + checkFold(embedId, (zoomIn, action) => { /// #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(); hideKeyboardToolbar(); /// #else @@ -1914,23 +1913,23 @@ export class WYSIWYG { app: protyle.app, id: embedId, 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) { openFileById({ app: protyle.app, id: embedId, 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) { openFileById({ app: protyle.app, 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, }); } else if (!protyle.disabled) { @@ -1942,7 +1941,7 @@ export class WYSIWYG { })); } /// #endif - }); + }) event.stopPropagation(); return; } diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index a5c08f7ba40..e887193c36f 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -39,7 +39,7 @@ import {newFileContentBySelect, rename, replaceFileName} from "../../editor/rena import {insertEmptyBlock, jumpToParentNext} from "../../block/util"; import {isLocalPath, pathPosix} from "../../util/pathName"; /// #if !MOBILE -import {openBy, openFileById} from "../../editor/util"; +import {checkFold, openBy, openFileById} from "../../editor/util"; /// #endif import { alignImgCenter, alignImgLeft, @@ -1525,52 +1525,52 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { if (refElement) { const id = refElement.getAttribute("data-id"); if (matchHotKey(window.siyuan.config.keymap.editor.general.openBy.custom, event)) { - fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { + checkFold(id, (zoomIn, action) => { openFileById({ app: protyle.app, 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.stopPropagation(); return true; } else if (matchHotKey(window.siyuan.config.keymap.editor.general.refTab.custom, event)) { // 打开块引和编辑器中引用、反链、书签中点击事件需保持一致,都加载上下文 - fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { + checkFold(id, (zoomIn) => { openFileById({ app: protyle.app, 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, - zoomIn: foldResponse.data + zoomIn }); }); event.preventDefault(); event.stopPropagation(); return true; } else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertRight.custom, event)) { - fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { + checkFold(id, (zoomIn, action) => { openFileById({ app: protyle.app, id, 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.stopPropagation(); return true; } else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertBottom.custom, event)) { - fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { + checkFold(id, (zoomIn, action) => { openFileById({ app: protyle.app, id, 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(); diff --git a/app/src/search/util.ts b/app/src/search/util.ts index ce7a39118d7..5ca1a5a238c 100644 --- a/app/src/search/util.ts +++ b/app/src/search/util.ts @@ -1081,7 +1081,7 @@ export const getArticle = (options: { edit: Protyle value: string, }) => { - fetchPost("/api/block/checkBlockFold", {id: options.id}, (foldResponse) => { + checkFold(options.id, (zoomIn) => { options.edit.protyle.scroll.lastScrollTop = 0; addLoading(options.edit.protyle); fetchPost("/api/filetree/getDoc", { @@ -1089,14 +1089,14 @@ export const getArticle = (options: { query: options.value, queryMethod: options.config.method, 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 => { onGet({ data: getResponse, 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"]`); if (matchElement) {