Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 63 additions & 24 deletions app/src/editor/openLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,34 @@ export const processSYLink = (app: App, url: string) => {
return false;
};

const resolveOpenAction = (ctrlIsPressed: boolean, event?: MouseEvent): Config.TLinkOpenAction => {
const config = window.siyuan.config.editor.openLink;
if (event && event.altKey) {
return config.altClick;
}
if (event && event.shiftKey) {
return config.shiftClick;
}
if (ctrlIsPressed) {
return config.ctrlClick;
}
return config.click;
};

export const openLink = (protyle: IProtyle, aLink: string, event?: MouseEvent, ctrlIsPressed = false) => {
let linkAddress = Lute.UnEscapeHTMLStr(aLink);
const action = resolveOpenAction(ctrlIsPressed, event);

let preventDefaultCalled = false;
for (const plugin of protyle.app.plugins) {
if (!plugin.eventBus.emit("open-link", {url: linkAddress, action: action})) {
preventDefaultCalled = true;
}
}
if (preventDefaultCalled) {
return;
}

let pdfParams;
if (isLocalPath(linkAddress) && !linkAddress.startsWith("file://") && linkAddress.indexOf(".pdf") > -1) {
const pdfAddress = linkAddress.split("/");
Expand All @@ -120,33 +146,46 @@ export const openLink = (protyle: IProtyle, aLink: string, event?: MouseEvent, c
(linkAddress.endsWith(".pdf") && linkAddress.startsWith("assets/"))
)
) {
if (event && event.altKey) {
openAsset(protyle.app, linkAddress, pdfParams);
} else if (event && event.shiftKey) {
/// #if !BROWSER
openBy(linkAddress, "app");
/// #else
openByMobile(linkAddress);
/// #endif
} else if (ctrlIsPressed) {
/// #if !BROWSER
openBy(linkAddress, "folder");
/// #else
openByMobile(linkAddress);
/// #endif
} else {
openAsset(protyle.app, linkAddress, pdfParams, !window.siyuan.config.fileTree.noSplitScreenWhenOpenTab ? "right" : null);
switch (action) {
case "current-tab":
openAsset(protyle.app, linkAddress, pdfParams);
break;
Comment on lines +149 to +152
case "right-tab":
const isOpenRight = !window.siyuan.config.fileTree.noSplitScreenWhenOpenTab ? "right" : null
openAsset(protyle.app, linkAddress, pdfParams, isOpenRight);
break;
Comment on lines +153 to +156
Comment on lines +153 to +156
case "open-app":
/// #if !BROWSER
openBy(linkAddress, "app");
/// #else
openByMobile(linkAddress);
/// #endif
break;
case "show-folder":
/// #if !BROWSER
openBy(linkAddress, "folder");
/// #else
openByMobile(linkAddress);
/// #endif
break;
}
} else {
/// #if !BROWSER
if (ctrlIsPressed) {
openBy(linkAddress, "folder");
} else {
openBy(linkAddress, "app");
switch (action) {
case "show-folder":
/// #if !BROWSER
openBy(linkAddress, "folder");
/// #else
openByMobile(linkAddress);
/// #endif
break;
default:
/// #if !BROWSER
openBy(linkAddress, "app");
/// #else
openByMobile(linkAddress);
/// #endif
break;
}
/// #else
openByMobile(linkAddress);
/// #endif
}
} else if (linkAddress) {
if (0 > linkAddress.indexOf(":")) {
Expand Down
19 changes: 19 additions & 0 deletions app/src/types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,21 @@ declare namespace Config {
inlineMark: boolean;
}

/**
* Link open action type
*/
type TLinkOpenAction = "current-tab" | "right-tab" | "open-app" | "show-folder";

/**
* Link open behavior configuration
*/
interface IOpenLink {
click: TLinkOpenAction;
ctrlClick: TLinkOpenAction;
altClick: TLinkOpenAction;
shiftClick: TLinkOpenAction;
}

/**
* SiYuan editor related configuration
*/
Expand Down Expand Up @@ -504,6 +519,10 @@ declare namespace Config {
* Whether to enable the `[[` symbol to search only for document blocks
*/
onlySearchForDoc: boolean;
/**
* Link open behavior configuration
*/
openLink: IOpenLink;
/**
* PlantUML rendering service address
*/
Expand Down
2 changes: 1 addition & 1 deletion app/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type TEventBus = "ws-main" | "sync-start" | "sync-end" | "sync-fail" |
"open-noneditableblock" |
"open-menu-blockref" | "open-menu-fileannotationref" | "open-menu-tag" | "open-menu-link" | "open-menu-image" |
"open-menu-av" | "open-menu-content" | "open-menu-breadcrumbmore" | "open-menu-doctree" | "open-menu-inbox" |
"open-siyuan-url-plugin" | "open-siyuan-url-block" | "opened-notebook" |
"open-siyuan-url-plugin" | "open-siyuan-url-block" | "open-link" | "opened-notebook" |
"closed-notebook" |
"paste" |
"input-search" |
Expand Down
9 changes: 9 additions & 0 deletions kernel/conf/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ package conf

import "github.com/siyuan-note/siyuan/kernel/util"

type OpenLink struct {
Click string `json:"click"` // 普通点击链接打开方式
CtrlClick string `json:"ctrlClick"` // Ctrl+点击链接打开方式
AltClick string `json:"altClick"` // Alt+点击链接打开方式
ShiftClick string `json:"shiftClick"` // Shift+点击链接打开方式
}

type Editor struct {
AllowSVGScript bool `json:"allowSVGScript"` // 允许执行 SVG 内脚本
AllowHTMLBLockScript bool `json:"allowHTMLBLockScript"` // 允许执行 HTML 块内脚本
Expand All @@ -38,6 +45,7 @@ type Editor struct {
VirtualBlockRefExclude string `json:"virtualBlockRefExclude"` // 虚拟引用关键字排除列表
VirtualBlockRefInclude string `json:"virtualBlockRefInclude"` // 虚拟引用关键字包含列表
BlockRefDynamicAnchorTextMaxLen int `json:"blockRefDynamicAnchorTextMaxLen"` // 块引动态锚文本最大长度
OpenLink *OpenLink `json:"openLink"` // 链接打开行为配置
PlantUMLServePath string `json:"plantUMLServePath"` // PlantUML 伺服地址
FullWidth bool `json:"fullWidth"` // 是否使用最大宽度
KaTexMacros string `json:"katexMacros"` // KeTex 宏定义
Expand Down Expand Up @@ -82,6 +90,7 @@ func NewEditor() *Editor {
Emoji: []string{},
VirtualBlockRef: false,
BlockRefDynamicAnchorTextMaxLen: 96,
OpenLink: &OpenLink{Click: "right-tab", CtrlClick: "show-folder", AltClick: "current-tab", ShiftClick: "open-app"},
PlantUMLServePath: "https://www.plantuml.com/plantuml/svg/~1",
FullWidth: true,
KaTexMacros: "{}",
Expand Down
3 changes: 3 additions & 0 deletions kernel/model/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ func InitConf() {
if 5120 < Conf.Editor.BlockRefDynamicAnchorTextMaxLen {
Conf.Editor.BlockRefDynamicAnchorTextMaxLen = 5120
}
if nil == Conf.Editor.OpenLink {
Conf.Editor.OpenLink = defaultEditor.OpenLink
}
Comment on lines +293 to +295
if 1440 < Conf.Editor.GenerateHistoryInterval {
Conf.Editor.GenerateHistoryInterval = 1440
}
Expand Down
Loading