🎨 桌面端拖入文件时可选择 使用 file:// 绝对路径并链接
或 复制为资源文件并插入
https://github.com/siyuan-note/siyuan/issues/5369
This commit is contained in:
parent
40ade96b89
commit
6d99389c01
3 changed files with 15 additions and 9 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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", {});
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue