An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: https://github.com/siyuan-note/siyuan/issues/11157
Vanessae831f07eb242
diff --git a/app/src/editor/util.ts b/app/src/editor/util.tsindex 2c0f8d16e3..04bd9a3b70 100644--- a/app/src/editor/util.ts+++ b/app/src/editor/util.ts@@ -5,7 +5,7 @@ import {getInstanceById, getWndByLayout, pdfIsLoading, setPanelFocus} from "../limport {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+}diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex 52a8238f0c..f682f9d5ca 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -58,7 +58,7 @@ import {blockRender} from "../render/blockRender";/// #if !MOBILEimport {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";/// #elseimport {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;}diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.tsindex 1322c9568b..e6a4cd8379 100644--- a/app/src/protyle/wysiwyg/keydown.ts+++ b/app/src/protyle/wysiwyg/keydown.ts@@ -38,7 +38,7 @@ import {newFileContentBySelect, rename, replaceFileName} from "../../editor/renaimport {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";/// #endifimport {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);