From 5be6c0e2a9aa1a21a93197aab0ea902ce702e4c5 Mon Sep 17 00:00:00 2001 From: Jeffrey Chen <78434827+TCOTC@users.noreply.github.com> Date: Sat, 7 Mar 2026 23:03:37 +0800 Subject: [PATCH] :art: Improve the database assets field file opening (#17054) --- app/src/protyle/render/av/blockAttr.ts | 4 ++-- app/src/protyle/render/av/openMenuPanel.ts | 28 ++++------------------ 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/app/src/protyle/render/av/blockAttr.ts b/app/src/protyle/render/av/blockAttr.ts index 5bc73d0f4..36362d0e6 100644 --- a/app/src/protyle/render/av/blockAttr.ts +++ b/app/src/protyle/render/av/blockAttr.ts @@ -16,7 +16,7 @@ import {webUtils} from "electron"; /// #endif import {isBrowser} from "../../../util/functions"; import {Constants} from "../../../constants"; -import {getCompressURL} from "../../../util/image"; +import {getCompressURL, removeCompressURL} from "../../../util/image"; const genAVRollupHTML = (value: IAVCellValue) => { let html = ""; @@ -502,7 +502,7 @@ const openEdit = (protyle: IProtyle, element: HTMLElement, event: MouseEvent) => }); } else { if (target.tagName === "IMG") { - previewImages([target.getAttribute("src")]); + previewImages([removeCompressURL(target.getAttribute("src"))]); } else { openLink(protyle, target.dataset.url, event, event.ctrlKey || event.metaKey); } diff --git a/app/src/protyle/render/av/openMenuPanel.ts b/app/src/protyle/render/av/openMenuPanel.ts index 17c584dc7..275e2507d 100644 --- a/app/src/protyle/render/av/openMenuPanel.ts +++ b/app/src/protyle/render/av/openMenuPanel.ts @@ -21,12 +21,10 @@ import {updateAttrViewCellAnimation} from "./action"; import {addAssetLink, bindAssetEvent, editAssetItem, getAssetHTML, updateAssetCell} from "./asset"; import {Constants} from "../../../constants"; import {hideElements} from "../../ui/hideElements"; -import {isLocalPath, pathPosix} from "../../../util/pathName"; +import {pathPosix} from "../../../util/pathName"; import {openEmojiPanel, unicode2Emoji} from "../../../emoji"; -import {getSearch, isMobile} from "../../../util/functions"; -/// #if !MOBILE -import {openAsset} from "../../../editor/util"; -/// #endif +import {isMobile} from "../../../util/functions"; +import {openLink} from "../../../editor/openLink"; import {previewAttrViewImages} from "../../preview/image"; import {assetMenu} from "../../../menus/protyle"; import { @@ -1358,29 +1356,13 @@ export const openMenuPanel = (options: { event.stopPropagation(); break; } else if (type === "openAssetItem") { - const assetType = target.parentElement.dataset.type; const assetLink = target.parentElement.dataset.content; - /// #if !MOBILE - const suffix = pathPosix().extname(assetLink); - if (assetType === "image") { - previewAttrViewImages(assetLink, avID, options.blockElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW), - options.blockElement.querySelector('[data-type="av-search"]')?.textContent.trim() || ""); - } else if (isLocalPath(assetLink) && assetType === "file" && ( - (suffix === ".pdf" && !assetLink.startsWith("file://")) || - Constants.SIYUAN_ASSETS_AUDIO.concat(Constants.SIYUAN_ASSETS_VIDEO, Constants.SIYUAN_ASSETS_IMAGE).includes(suffix) - )) { - openAsset(options.protyle.app, assetLink.trim(), parseInt(getSearch("page", assetLink)), "right"); - } else { - window.open(assetLink); - } - /// #else - if (assetType === "image") { + if (target.parentElement.dataset.type === "image") { previewAttrViewImages(assetLink, avID, options.blockElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW), options.blockElement.querySelector('[data-type="av-search"]')?.textContent.trim() || ""); } else { - window.open(assetLink); + openLink(options.protyle, assetLink, event, event.ctrlKey || event.metaKey); } - /// #endif event.preventDefault(); event.stopPropagation(); break;