mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 16:40:13 +01:00
🎨 桌面端拖入文件时可选择 使用 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 {getAllModels} from "../../layout/getAll";
|
||||||
import {updatePanelByEditor} from "../../editor/util";
|
import {updatePanelByEditor} from "../../editor/util";
|
||||||
/// #endif
|
/// #endif
|
||||||
|
import * as path from "path";
|
||||||
import {Editor} from "../../editor";
|
import {Editor} from "../../editor";
|
||||||
import {blockRender} from "../markdown/blockRender";
|
import {blockRender} from "../markdown/blockRender";
|
||||||
import {processRender} from "./processCode";
|
import {processRender} from "./processCode";
|
||||||
|
|
@ -23,7 +24,6 @@ import {highlightRender} from "../markdown/highlightRender";
|
||||||
import {uploadLocalFiles} from "../upload";
|
import {uploadLocalFiles} from "../upload";
|
||||||
import {MenuItem} from "../../menus/Menu";
|
import {MenuItem} from "../../menus/Menu";
|
||||||
import {insertHTML} from "./insertHTML";
|
import {insertHTML} from "./insertHTML";
|
||||||
import {pathPosix} from "../../util/pathName";
|
|
||||||
|
|
||||||
const dragSb = (protyle: IProtyle, sourceElements: Element[], targetElement: Element, isBottom: boolean, direct: "col" | "row") => {
|
const dragSb = (protyle: IProtyle, sourceElements: Element[], targetElement: Element, isBottom: boolean, direct: "col" | "row") => {
|
||||||
const isSameDoc = protyle.element.contains(sourceElements[0]);
|
const isSameDoc = protyle.element.contains(sourceElements[0]);
|
||||||
|
|
@ -718,7 +718,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
click() {
|
click() {
|
||||||
let fileText = "";
|
let fileText = "";
|
||||||
files.forEach((item) => {
|
files.forEach((item) => {
|
||||||
fileText += `[${pathPosix().basename(item)}](file://${item})\n`;
|
fileText += `[${path.basename(item)}](file://${item})\n`;
|
||||||
});
|
});
|
||||||
insertHTML(protyle.lute.SpinBlockDOM(fileText), protyle);
|
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 }) => {
|
export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEvent) & { target: HTMLElement }) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
let textHTML;
|
let textHTML;
|
||||||
let textPlain;
|
let textPlain;
|
||||||
let files;
|
let files;
|
||||||
|
|
@ -87,6 +86,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
if (!textHTML && !textPlain && ("clipboardData" in event)) {
|
if (!textHTML && !textPlain && ("clipboardData" in event)) {
|
||||||
if ("darwin" === window.siyuan.config.system.os) {
|
if ("darwin" === window.siyuan.config.system.os) {
|
||||||
|
/// #if !BROWSER
|
||||||
const xmlString = clipboard.read("NSFilenamesPboardType");
|
const xmlString = clipboard.read("NSFilenamesPboardType");
|
||||||
const domParser = new DOMParser();
|
const domParser = new DOMParser();
|
||||||
const xmlDom = domParser.parseFromString(xmlString, "application/xml");
|
const xmlDom = domParser.parseFromString(xmlString, "application/xml");
|
||||||
|
|
@ -96,6 +96,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
||||||
});
|
});
|
||||||
uploadLocalFiles(localFiles, protyle);
|
uploadLocalFiles(localFiles, protyle);
|
||||||
writeText("");
|
writeText("");
|
||||||
|
/// #endif
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
const xmlString = await fetchSyncPost("/api/clipboard/readFilePaths", {});
|
const xmlString = await fetchSyncPost("/api/clipboard/readFilePaths", {});
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ import {
|
||||||
focusByRange,
|
focusByRange,
|
||||||
focusByWbr,
|
focusByWbr,
|
||||||
getEditorRange,
|
getEditorRange,
|
||||||
getSelectionOffset, selectAll,
|
getSelectionOffset,
|
||||||
|
selectAll,
|
||||||
setFirstNodeRange,
|
setFirstNodeRange,
|
||||||
setLastNodeRange
|
setLastNodeRange
|
||||||
} from "../util/selection";
|
} from "../util/selection";
|
||||||
|
|
@ -22,7 +23,9 @@ import {
|
||||||
getLastBlock,
|
getLastBlock,
|
||||||
getNextBlock,
|
getNextBlock,
|
||||||
getPreviousBlock,
|
getPreviousBlock,
|
||||||
getTopAloneElement, hasNextSibling, hasPreviousSibling,
|
getTopAloneElement,
|
||||||
|
hasNextSibling,
|
||||||
|
hasPreviousSibling,
|
||||||
isNotEditBlock,
|
isNotEditBlock,
|
||||||
} from "./getBlock";
|
} from "./getBlock";
|
||||||
import {matchHotKey} from "../util/hotKey";
|
import {matchHotKey} from "../util/hotKey";
|
||||||
|
|
@ -39,10 +42,11 @@ import {fontEvent} from "../toolbar/Font";
|
||||||
import {listIndent, listOutdent, updateListOrder} from "./list";
|
import {listIndent, listOutdent, updateListOrder} from "./list";
|
||||||
import {newFileBySelect, newFileContentBySelect, rename, replaceFileName} from "../../editor/rename";
|
import {newFileBySelect, newFileContentBySelect, rename, replaceFileName} from "../../editor/rename";
|
||||||
import {insertEmptyBlock, jumpToParentNext} from "../../block/util";
|
import {insertEmptyBlock, jumpToParentNext} from "../../block/util";
|
||||||
import {isLocalPath, pathPosix} from "../../util/pathName";
|
import {isLocalPath} from "../../util/pathName";
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
import {clipboard} from "electron";
|
import {clipboard} from "electron";
|
||||||
import {getCurrentWindow} from "@electron/remote";
|
import {getCurrentWindow} from "@electron/remote";
|
||||||
|
import * as path from "path";
|
||||||
/// #endif
|
/// #endif
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
import {openBy, openFileById} from "../../editor/util";
|
import {openBy, openFileById} from "../../editor/util";
|
||||||
|
|
@ -1570,6 +1574,9 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
|
|
||||||
/// #if !BROWSER && !MOBILE
|
/// #if !BROWSER && !MOBILE
|
||||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.pasteAsPlainText.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.pasteAsPlainText.custom, event)) {
|
||||||
|
event.returnValue = false;
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
let localFiles: string[] = [];
|
let localFiles: string[] = [];
|
||||||
if ("darwin" === window.siyuan.config.system.os) {
|
if ("darwin" === window.siyuan.config.system.os) {
|
||||||
const xmlString = clipboard.read("NSFilenamesPboardType");
|
const xmlString = clipboard.read("NSFilenamesPboardType");
|
||||||
|
|
@ -1587,7 +1594,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
if (localFiles.length > 0) {
|
if (localFiles.length > 0) {
|
||||||
let fileText = ""
|
let fileText = ""
|
||||||
localFiles.forEach((item) => {
|
localFiles.forEach((item) => {
|
||||||
fileText += `[${pathPosix().basename(item)}](file://${item})\n`;
|
fileText += `[${path.basename(item)}](file://${item})\n`;
|
||||||
});
|
});
|
||||||
insertHTML(protyle.lute.SpinBlockDOM(fileText), protyle);
|
insertHTML(protyle.lute.SpinBlockDOM(fileText), protyle);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1596,8 +1603,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
getCurrentWindow().webContents.pasteAndMatchStyle();
|
getCurrentWindow().webContents.pasteAndMatchStyle();
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue