This commit is contained in:
parent
46ed19f18e
commit
e831f07eb2
3 changed files with 72 additions and 57 deletions
|
@ -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, pathPosix, showFileInFolder} from "../util/pathName";
|
||||
import {getDisplayName, isLocalPath, pathPosix, showFileInFolder} from "../util/pathName";
|
||||
import {Constants} from "../constants";
|
||||
import {setEditMode} from "../protyle/util/setEditMode";
|
||||
import {Files} from "../layout/dock/Files";
|
||||
|
@ -22,13 +22,14 @@ import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName,} from "..
|
|||
import {zoomOut} from "../menus/protyle";
|
||||
import {countBlockWord, countSelectWord} from "../layout/status";
|
||||
import {showMessage} from "../dialog/message";
|
||||
import {objEquals} from "../util/functions";
|
||||
import {getSearch, 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,
|
||||
|
@ -694,3 +695,59 @@ export const openBy = (url: string, type: "folder" | "app") => {
|
|||
}
|
||||
/// #endif
|
||||
};
|
||||
|
||||
export const openLink = (protyle: IProtyle, aLink: string, event: MouseEvent | KeyboardEvent, ctrlIsPressed = false) => {
|
||||
let linkAddress = Lute.UnEscapeHTMLStr(aLink);
|
||||
/// #if MOBILE
|
||||
openByMobile(linkAddress);
|
||||
/// #else
|
||||
if (isLocalPath(linkAddress)) {
|
||||
const linkPathname = linkAddress.split("?page")[0];
|
||||
if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname(linkPathname)) &&
|
||||
(!linkPathname.endsWith(".pdf") ||
|
||||
(linkPathname.endsWith(".pdf") && !linkAddress.startsWith("file://")))
|
||||
) {
|
||||
if (event && event.altKey) {
|
||||
openAsset(protyle.app, linkAddress, parseInt(getSearch("page", linkAddress)));
|
||||
} 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, linkPathname, parseInt(getSearch("page", linkAddress)), "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
|
||||
}
|
||||
|
|
|
@ -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 {openAsset, openBy, openFileById, openLink} from "../../editor/util";
|
||||
import {openGlobalSearch} from "../../search/util";
|
||||
/// #else
|
||||
import {popSearch} from "../../mobile/menu/search";
|
||||
|
@ -2125,59 +2125,7 @@ export class WYSIWYG {
|
|||
if (aElement && range.toString() === "" && aLink) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
let linkAddress = Lute.UnEscapeHTMLStr(aLink);
|
||||
/// #if MOBILE
|
||||
openByMobile(linkAddress);
|
||||
/// #else
|
||||
if (isLocalPath(linkAddress)) {
|
||||
const linkPathname = linkAddress.split("?page")[0];
|
||||
if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname(linkPathname)) &&
|
||||
(!linkPathname.endsWith(".pdf") ||
|
||||
(linkPathname.endsWith(".pdf") && !linkAddress.startsWith("file://")))
|
||||
) {
|
||||
if (event.altKey) {
|
||||
openAsset(protyle.app, linkAddress, parseInt(getSearch("page", linkAddress)));
|
||||
} else if (ctrlIsPressed) {
|
||||
/// #if !BROWSER
|
||||
openBy(linkAddress, "folder");
|
||||
/// #else
|
||||
openByMobile(linkAddress);
|
||||
/// #endif
|
||||
} else if (event.shiftKey) {
|
||||
/// #if !BROWSER
|
||||
openBy(linkAddress, "app");
|
||||
/// #else
|
||||
openByMobile(linkAddress);
|
||||
/// #endif
|
||||
} else {
|
||||
openAsset(protyle.app, linkPathname, parseInt(getSearch("page", linkAddress)), "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
|
||||
openLink(protyle, aLink, event, ctrlIsPressed);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ import {newFileContentBySelect, rename, replaceFileName} from "../../editor/rena
|
|||
import {insertEmptyBlock, jumpToParentNext} from "../../block/util";
|
||||
import {isLocalPath} from "../../util/pathName";
|
||||
/// #if !MOBILE
|
||||
import {openBy, openFileById} from "../../editor/util";
|
||||
import {openBy, openFileById, openLink} from "../../editor/util";
|
||||
/// #endif
|
||||
import {
|
||||
alignImgCenter,
|
||||
|
@ -1579,6 +1579,16 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
}
|
||||
/// #endif
|
||||
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.openBy.custom, event)) {
|
||||
const aElement = hasClosestByAttribute(range.startContainer, "data-type", "a");
|
||||
if (aElement) {
|
||||
openLink(protyle, aElement.getAttribute("data-href"), event, false);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 置于最后,太多快捷键会使用到选中元素
|
||||
if (isNotCtrl(event) && event.key !== "Backspace" && event.key !== "Escape" && event.key !== "Delete" && !event.shiftKey && !event.altKey && event.key !== "Enter") {
|
||||
hideElements(["select"], protyle);
|
||||
|
|
Loading…
Add table
Reference in a new issue