diff --git a/app/src/block/util.ts b/app/src/block/util.ts index 2861826c8..3f0a6ff0e 100644 --- a/app/src/block/util.ts +++ b/app/src/block/util.ts @@ -1,6 +1,6 @@ -import {focusBlock, focusByWbr, getEditorRange} from "../protyle/util/selection"; -import {hasClosestBlock, hasClosestByClassName} from "../protyle/util/hasClosest"; -import {getNextBlock, getTopAloneElement} from "../protyle/wysiwyg/getBlock"; +import {focusByWbr, getEditorRange} from "../protyle/util/selection"; +import {hasClosestBlock} from "../protyle/util/hasClosest"; +import {getTopAloneElement} from "../protyle/wysiwyg/getBlock"; import {genListItemElement, updateListOrder} from "../protyle/wysiwyg/list"; import {transaction, updateTransaction} from "../protyle/wysiwyg/transaction"; import {scrollCenter} from "../util/highlightById"; @@ -9,6 +9,7 @@ import {hideElements} from "../protyle/ui/hideElements"; import {blockRender} from "../protyle/render/blockRender"; import {fetchPost} from "../util/fetch"; import {openFileById} from "../editor/util"; +import {openMobileFileById} from "../mobile/editor"; export const cancelSB = (protyle: IProtyle, nodeElement: Element) => { const doOperations: IOperation[] = []; @@ -80,12 +81,15 @@ export const jumpToParent = (protyle: IProtyle, nodeElement: Element, type: "par if (!targetId) { return; } - + /// #if !MOBILE openFileById({ app: protyle.app, id: targetId, action: [Constants.CB_GET_FOCUS, targetId !== protyle.block.rootID && protyle.block.showAll ? Constants.CB_GET_ALL : ""] }) + /// #else + openMobileFileById(protyle.app, targetId, [Constants.CB_GET_FOCUS, targetId !== protyle.block.rootID && protyle.block.showAll ? Constants.CB_GET_ALL : ""]); + /// #endif }); }; diff --git a/app/src/editor/openLink.ts b/app/src/editor/openLink.ts new file mode 100644 index 000000000..e0106e5a1 --- /dev/null +++ b/app/src/editor/openLink.ts @@ -0,0 +1,75 @@ +import {isLocalPath, pathPosix} from "../util/pathName"; +/// #if !BROWSER +import {shell} from "electron"; +/// #endif +import {getSearch} from "../util/functions"; +import {openByMobile} from "../protyle/util/compatibility"; +import {Constants} from "../constants"; +import {showMessage} from "../dialog/message"; +import {openAsset, openBy} from "./util"; + +export const openLink = (protyle: IProtyle, aLink: string, event?: MouseEvent, ctrlIsPressed = false) => { + let linkAddress = Lute.UnEscapeHTMLStr(aLink); + let pdfParams; + if (isLocalPath(linkAddress) && !linkAddress.startsWith("file://") && linkAddress.indexOf(".pdf") > -1) { + const pdfAddress = linkAddress.split("/"); + if (pdfAddress.length === 3 && pdfAddress[0] === "assets" && pdfAddress[1].endsWith(".pdf") && /\d{14}-\w{7}/.test(pdfAddress[2])) { + linkAddress = `assets/${pdfAddress[1]}`; + pdfParams = pdfAddress[2]; + } else { + pdfParams = parseInt(getSearch("page", linkAddress)); + linkAddress = linkAddress.split("?page")[0]; + } + } + /// #if MOBILE + openByMobile(linkAddress); + /// #else + if (isLocalPath(linkAddress)) { + if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname(linkAddress)) && + (!linkAddress.endsWith(".pdf") || + (linkAddress.endsWith(".pdf") && !linkAddress.startsWith("file://"))) + ) { + if (event && event.altKey) { + openAsset(protyle.app, linkAddress, pdfParams); + } else if (ctrlIsPressed) { + /// #if !BROWSER + openBy(linkAddress, "folder"); + /// #else + openByMobile(linkAddress); + /// #endif + } else if (event && event.shiftKey) { + /// #if !BROWSER + openBy(linkAddress, "app"); + /// #else + openByMobile(linkAddress); + /// #endif + } else { + openAsset(protyle.app, linkAddress, pdfParams, "right"); + } + } else { + /// #if !BROWSER + if (ctrlIsPressed) { + openBy(linkAddress, "folder"); + } else { + openBy(linkAddress, "app"); + } + /// #else + openByMobile(linkAddress); + /// #endif + } + } else if (linkAddress) { + if (0 > linkAddress.indexOf(":")) { + // 使用 : 判断,不使用 :// 判断 Open external application protocol invalid https://github.com/siyuan-note/siyuan/issues/10075 + // Support click to open hyperlinks like `www.foo.com` https://github.com/siyuan-note/siyuan/issues/9986 + linkAddress = `https://${linkAddress}`; + } + /// #if !BROWSER + shell.openExternal(linkAddress).catch((e) => { + showMessage(e); + }); + /// #else + openByMobile(linkAddress); + /// #endif + } + /// #endif +}; diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index cedc8b20e..2c0f8d16e 100644 --- a/app/src/editor/util.ts +++ b/app/src/editor/util.ts @@ -5,7 +5,7 @@ import {getInstanceById, getWndByLayout, pdfIsLoading, setPanelFocus} from "../l import {getDockByType} from "../layout/tabUtil"; import {getAllModels, getAllTabs} from "../layout/getAll"; import {highlightById, scrollCenter} from "../util/highlightById"; -import {getDisplayName, isLocalPath, pathPosix, showFileInFolder} from "../util/pathName"; +import {getDisplayName, pathPosix, showFileInFolder} from "../util/pathName"; import {Constants} from "../constants"; import {setEditMode} from "../protyle/util/setEditMode"; import {Files} from "../layout/dock/Files"; @@ -22,14 +22,13 @@ import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName,} from ".. import {zoomOut} from "../menus/protyle"; import {countBlockWord, countSelectWord} from "../layout/status"; import {showMessage} from "../dialog/message"; -import {getSearch, objEquals} from "../util/functions"; +import {objEquals} from "../util/functions"; import {resize} from "../protyle/util/resize"; import {Search} from "../search"; import {App} from "../index"; import {newCardModel} from "../card/newCardTab"; import {preventScroll} from "../protyle/scroll/preventScroll"; import {clearOBG} from "../layout/dock/util"; -import {openByMobile} from "../protyle/util/compatibility"; export const openFileById = async (options: { app: App, @@ -695,69 +694,3 @@ export const openBy = (url: string, type: "folder" | "app") => { } /// #endif }; - -export const openLink = (protyle: IProtyle, aLink: string, event?: MouseEvent, ctrlIsPressed = false) => { - let linkAddress = Lute.UnEscapeHTMLStr(aLink); - let pdfParams; - if (isLocalPath(linkAddress) && !linkAddress.startsWith("file://") && linkAddress.indexOf(".pdf") > -1) { - const pdfAddress = linkAddress.split("/"); - if (pdfAddress.length === 3 && pdfAddress[0] === "assets" && pdfAddress[1].endsWith(".pdf") && /\d{14}-\w{7}/.test(pdfAddress[2])) { - linkAddress = `assets/${pdfAddress[1]}`; - pdfParams = pdfAddress[2]; - } else { - pdfParams = parseInt(getSearch("page", linkAddress)); - linkAddress = linkAddress.split("?page")[0]; - } - } - /// #if MOBILE - openByMobile(linkAddress); - /// #else - if (isLocalPath(linkAddress)) { - if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname(linkAddress)) && - (!linkAddress.endsWith(".pdf") || - (linkAddress.endsWith(".pdf") && !linkAddress.startsWith("file://"))) - ) { - if (event && event.altKey) { - openAsset(protyle.app, linkAddress, pdfParams); - } else if (ctrlIsPressed) { - /// #if !BROWSER - openBy(linkAddress, "folder"); - /// #else - openByMobile(linkAddress); - /// #endif - } else if (event && event.shiftKey) { - /// #if !BROWSER - openBy(linkAddress, "app"); - /// #else - openByMobile(linkAddress); - /// #endif - } else { - openAsset(protyle.app, linkAddress, pdfParams, "right"); - } - } else { - /// #if !BROWSER - if (ctrlIsPressed) { - openBy(linkAddress, "folder"); - } else { - openBy(linkAddress, "app"); - } - /// #else - openByMobile(linkAddress); - /// #endif - } - } else if (linkAddress) { - if (0 > linkAddress.indexOf(":")) { - // 使用 : 判断,不使用 :// 判断 Open external application protocol invalid https://github.com/siyuan-note/siyuan/issues/10075 - // Support click to open hyperlinks like `www.foo.com` https://github.com/siyuan-note/siyuan/issues/9986 - linkAddress = `https://${linkAddress}`; - } - /// #if !BROWSER - shell.openExternal(linkAddress).catch((e) => { - showMessage(e); - }); - /// #else - openByMobile(linkAddress); - /// #endif - } - /// #endif -};