Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: 桌面端拖入文件时可选择 `使用 file:// 绝对路径并链接` 或 `复制为资源文件并插入` https://github.com/siyuan-note/siyuan/issues/5369

Liang Ding6d99389c01ac
diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.ts
index 75d8fea875..28af884337 100644
--- a/app/src/protyle/util/editorCommonEvent.ts
+++ b/app/src/protyle/util/editorCommonEvent.ts
@@ -16,6 +16,7 @@ import {Tab} from "../../layout/Tab";
import {getAllModels} from "../../layout/getAll";
import {updatePanelByEditor} from "../../editor/util";
/// #endif
+import * as path from "path";
import {Editor} from "../../editor";
import {blockRender} from "../markdown/blockRender";
import {processRender} from "./processCode";
@@ -23,7 +24,6 @@ import {highlightRender} from "../markdown/highlightRender";
import {uploadLocalFiles} from "../upload";
import {MenuItem} from "../../menus/Menu";
import {insertHTML} from "./insertHTML";
-import {pathPosix} from "../../util/pathName";
const dragSb = (protyle: IProtyle, sourceElements: Element[], targetElement: Element, isBottom: boolean, direct: "col" | "row") => {
const isSameDoc = protyle.element.contains(sourceElements[0]);
@@ -718,7 +718,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
click() {
let fileText = "";
files.forEach((item) => {
- fileText += `[${pathPosix().basename(item)}](file://${item})\n`;
+ fileText += `[${path.basename(item)}](file://${item})\n`;
});
insertHTML(protyle.lute.SpinBlockDOM(fileText), protyle);
}
diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts
index ba2c3fb6b1..79f32ac972 100644
--- a/app/src/protyle/util/paste.ts
+++ b/app/src/protyle/util/paste.ts
@@ -69,7 +69,6 @@ export const pasteText = (protyle: IProtyle, textPlain: string, nodeElement: Ele
export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEvent) & { target: HTMLElement }) => {
event.stopPropagation();
event.preventDefault();
-
let textHTML;
let textPlain;
let files;
@@ -87,6 +86,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
/// #if !MOBILE
if (!textHTML && !textPlain && ("clipboardData" in event)) {
if ("darwin" === window.siyuan.config.system.os) {
+ /// #if !BROWSER
const xmlString = clipboard.read("NSFilenamesPboardType");
const domParser = new DOMParser();
const xmlDom = domParser.parseFromString(xmlString, "application/xml");
@@ -96,6 +96,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
});
uploadLocalFiles(localFiles, protyle);
writeText("");
+ /// #endif
return;
} else {
const xmlString = await fetchSyncPost("/api/clipboard/readFilePaths", {});
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index b55089f4b8..fe7caf2861 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -5,7 +5,8 @@ import {
focusByRange,
focusByWbr,
getEditorRange,
- getSelectionOffset, selectAll,
+ getSelectionOffset,
+ selectAll,
setFirstNodeRange,
setLastNodeRange
} from "../util/selection";
@@ -22,7 +23,9 @@ import {
getLastBlock,
getNextBlock,
getPreviousBlock,
- getTopAloneElement, hasNextSibling, hasPreviousSibling,
+ getTopAloneElement,
+ hasNextSibling,
+ hasPreviousSibling,
isNotEditBlock,
} from "./getBlock";
import {matchHotKey} from "../util/hotKey";
@@ -39,10 +42,11 @@ import {fontEvent} from "../toolbar/Font";
import {listIndent, listOutdent, updateListOrder} from "./list";
import {newFileBySelect, newFileContentBySelect, rename, replaceFileName} from "../../editor/rename";
import {insertEmptyBlock, jumpToParentNext} from "../../block/util";
-import {isLocalPath, pathPosix} from "../../util/pathName";
+import {isLocalPath} from "../../util/pathName";
/// #if !BROWSER
import {clipboard} from "electron";
import {getCurrentWindow} from "@electron/remote";
+import * as path from "path";
/// #endif
/// #if !MOBILE
import {openBy, openFileById} from "../../editor/util";
@@ -1570,6 +1574,9 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
/// #if !BROWSER && !MOBILE
if (matchHotKey(window.siyuan.config.keymap.editor.general.pasteAsPlainText.custom, event)) {
+ event.returnValue = false;
+ event.preventDefault();
+ event.stopPropagation();
let localFiles: string[] = [];
if ("darwin" === window.siyuan.config.system.os) {
const xmlString = clipboard.read("NSFilenamesPboardType");
@@ -1587,7 +1594,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
if (localFiles.length > 0) {
let fileText = ""
localFiles.forEach((item) => {
- fileText += `[${pathPosix().basename(item)}](file://${item})\n`;
+ fileText += `[${path.basename(item)}](file://${item})\n`;
});
insertHTML(protyle.lute.SpinBlockDOM(fileText), protyle);
} else {
@@ -1596,8 +1603,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
getCurrentWindow().webContents.pasteAndMatchStyle();
}, 100);
}
- event.preventDefault();
- event.stopPropagation();
return;
}