mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-01 10:20:16 +01:00
This commit is contained in:
parent
c1bde4f917
commit
950f60fe10
2 changed files with 17 additions and 9 deletions
|
|
@ -698,17 +698,27 @@ export const openBy = (url: string, type: "folder" | "app") => {
|
||||||
|
|
||||||
export const openLink = (protyle: IProtyle, aLink: string, event?: MouseEvent, ctrlIsPressed = false) => {
|
export const openLink = (protyle: IProtyle, aLink: string, event?: MouseEvent, ctrlIsPressed = false) => {
|
||||||
let linkAddress = Lute.UnEscapeHTMLStr(aLink);
|
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
|
/// #if MOBILE
|
||||||
openByMobile(linkAddress);
|
openByMobile(linkAddress);
|
||||||
/// #else
|
/// #else
|
||||||
if (isLocalPath(linkAddress)) {
|
if (isLocalPath(linkAddress)) {
|
||||||
const linkPathname = linkAddress.split("?page")[0];
|
if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname(linkAddress)) &&
|
||||||
if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname(linkPathname)) &&
|
(!linkAddress.endsWith(".pdf") ||
|
||||||
(!linkPathname.endsWith(".pdf") ||
|
(linkAddress.endsWith(".pdf") && !linkAddress.startsWith("file://")))
|
||||||
(linkPathname.endsWith(".pdf") && !linkAddress.startsWith("file://")))
|
|
||||||
) {
|
) {
|
||||||
if (event && event.altKey) {
|
if (event && event.altKey) {
|
||||||
openAsset(protyle.app, linkAddress, parseInt(getSearch("page", linkAddress)));
|
openAsset(protyle.app, linkAddress, pdfParams);
|
||||||
} else if (ctrlIsPressed) {
|
} else if (ctrlIsPressed) {
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
openBy(linkAddress, "folder");
|
openBy(linkAddress, "folder");
|
||||||
|
|
@ -722,7 +732,7 @@ export const openLink = (protyle: IProtyle, aLink: string, event?: MouseEvent, c
|
||||||
openByMobile(linkAddress);
|
openByMobile(linkAddress);
|
||||||
/// #endif
|
/// #endif
|
||||||
} else {
|
} else {
|
||||||
openAsset(protyle.app, linkPathname, parseInt(getSearch("page", linkAddress)), "right");
|
openAsset(protyle.app, linkAddress, pdfParams, "right");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
|
|
|
||||||
|
|
@ -2104,9 +2104,7 @@ export class WYSIWYG {
|
||||||
if (fileElement && range.toString() === "") {
|
if (fileElement && range.toString() === "") {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const fileIds = fileElement.getAttribute("data-id").split("/");
|
openLink(protyle, fileElement.getAttribute("data-id"), event, ctrlIsPressed);
|
||||||
const linkAddress = `assets/${fileIds[1]}`;
|
|
||||||
openLink(protyle, linkAddress, event, ctrlIsPressed);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue