Skip to content

Commit

Permalink
🎨 fix siyuan-note#9402
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Oct 11, 2023
1 parent eb93255 commit 7486e1a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
15 changes: 14 additions & 1 deletion app/src/protyle/render/av/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import {focusByRange} from "../../util/selection";
import {writeText} from "../../util/compatibility";
import {showMessage} from "../../../dialog/message";
import {previewImage} from "../../preview/image";
import {isLocalPath, pathPosix} from "../../../util/pathName";
import {Constants} from "../../../constants";
import {openAsset} from "../../../editor/util";
import {getSearch, isMobile} from "../../../util/functions";

export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLElement }) => {
const blockElement = hasClosestBlock(event.target);
Expand Down Expand Up @@ -127,7 +131,16 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
} else if (linkElement.classList.contains("b3-chip")) {
linkAddress = linkElement.dataset.url;
}
window.open(linkAddress);
const suffix = pathPosix().extname(linkAddress);
if (isLocalPath(linkAddress) && !isMobile() && (
[".pdf"].concat(Constants.SIYUAN_ASSETS_AUDIO).concat(Constants.SIYUAN_ASSETS_VIDEO).includes(suffix) && (
suffix !== ".pdf" || (suffix === ".pdf" && !linkAddress.startsWith("file://"))
)
)) {
openAsset(protyle.app, linkAddress.trim(), parseInt(getSearch("page", linkAddress)), "right");
} else {
window.open(linkAddress);
}
event.preventDefault();
event.stopPropagation();
return true;
Expand Down
4 changes: 2 additions & 2 deletions app/src/protyle/render/av/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ export const getAssetHTML = (data: IAVTable, cellElements: HTMLElement[]) => {
}
let contentHTML;
if (item.type === "image") {
contentHTML = `<span class="fn__flex-1">
contentHTML = `<span data-type="openAssetItem" class="fn__flex-1">
<img style="max-height: 180px;max-width: 360px;border-radius: var(--b3-border-radius);margin: 4px 0;" src="${item.content}"/>
</span>`;
} else {
contentHTML = `<span class="fn__ellipsis b3-menu__label" style="max-width: 360px">${item.name}</span>`;
contentHTML = `<span data-type="openAssetItem" class="fn__ellipsis b3-menu__label" style="max-width: 360px">${item.name}</span>`;
}

html += `<button class="b3-menu__item" draggable="true" data-name="${item.name}" data-type="${item.type}" data-content="${item.content}">
Expand Down
22 changes: 21 additions & 1 deletion app/src/protyle/render/av/openMenuPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ import {removeAttrViewColAnimation, updateAttrViewCellAnimation} from "./action"
import {addAssetLink, bindAssetEvent, editAssetItem, getAssetHTML, updateAssetCell} from "./asset";
import {Constants} from "../../../constants";
import {hideElements} from "../../ui/hideElements";
import {pathPosix} from "../../../util/pathName";
import {isLocalPath, pathPosix} from "../../../util/pathName";
import {openEmojiPanel, unicode2Emoji} from "../../../emoji";
import {getSearch, isMobile} from "../../../util/functions";
import {openAsset} from "../../../editor/util";
import {previewImage} from "../../preview/image";

export const openMenuPanel = (options: {
protyle: IProtyle,
Expand Down Expand Up @@ -741,6 +744,23 @@ export const openMenuPanel = (options: {
event.preventDefault();
event.stopPropagation();
break;
} else if (type === "openAssetItem") {
const assetLink = target.parentElement.dataset.content;
const suffix = pathPosix().extname(assetLink)
if (isLocalPath(assetLink) && !isMobile() && (
[".pdf"].concat(Constants.SIYUAN_ASSETS_AUDIO).concat(Constants.SIYUAN_ASSETS_VIDEO).includes(suffix) && (
suffix !== ".pdf" || ( suffix === ".pdf" && !assetLink.startsWith("file://"))
)
)) {
openAsset(options.protyle.app, assetLink.trim(), parseInt(getSearch("page", assetLink)), "right");
} else if (Constants.SIYUAN_ASSETS_IMAGE.includes(suffix)) {
previewImage(assetLink);
} else {
window.open(assetLink);
}
event.preventDefault();
event.stopPropagation();
break;
} else if (type === "editAssetItem") {
editAssetItem(options.protyle, data, options.cellElements, target.parentElement);
event.preventDefault();
Expand Down

0 comments on commit 7486e1a

Please sign in to comment.