mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 16:40:13 +01:00
This commit is contained in:
parent
af25cf1d7c
commit
ab41253192
3 changed files with 8 additions and 27 deletions
|
|
@ -124,10 +124,11 @@ const genUploadedLabel = (responseText: string, protyle: IProtyle) => {
|
||||||
insertHTML(protyle.lute.SpinBlockDOM(succFileText), protyle);
|
insertHTML(protyle.lute.SpinBlockDOM(succFileText), protyle);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const uploadLocalFiles = (files: string[], protyle: IProtyle) => {
|
export const uploadLocalFiles = (files: string[], protyle: IProtyle, isUpload:boolean) => {
|
||||||
const msgId = showMessage(window.siyuan.languages.uploading, 0);
|
const msgId = showMessage(window.siyuan.languages.uploading, 0);
|
||||||
fetchPost("/api/asset/insertLocalAssets", {
|
fetchPost("/api/asset/insertLocalAssets", {
|
||||||
assetPaths: files,
|
assetPaths: files,
|
||||||
|
isUpload,
|
||||||
id: protyle.block.rootID
|
id: protyle.block.rootID
|
||||||
}, (response) => {
|
}, (response) => {
|
||||||
hideMessage(msgId);
|
hideMessage(msgId);
|
||||||
|
|
@ -145,7 +146,7 @@ export const uploadFiles = (protyle: IProtyle, files: FileList | DataTransferIte
|
||||||
}
|
}
|
||||||
if (0 === fileItem.size && "" === fileItem.type && -1 === fileItem.name.indexOf(".")) {
|
if (0 === fileItem.size && "" === fileItem.type && -1 === fileItem.name.indexOf(".")) {
|
||||||
// 文件夹
|
// 文件夹
|
||||||
document.execCommand("insertHTML", false, `[${fileItem.name}](file://${fileItem.path})`);
|
uploadLocalFiles([fileItem.path], protyle, false);
|
||||||
} else {
|
} else {
|
||||||
fileList.push(fileItem);
|
fileList.push(fileItem);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -706,27 +706,10 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
focusByRange(document.caretRangeFromPoint(event.clientX, event.clientY));
|
focusByRange(document.caretRangeFromPoint(event.clientX, event.clientY));
|
||||||
if (event.dataTransfer.types[0] === "Files") {
|
if (event.dataTransfer.types[0] === "Files") {
|
||||||
const files: string[] = [];
|
const files: string[] = [];
|
||||||
let isAllFile = true;
|
|
||||||
for (let i = 0; i < event.dataTransfer.files.length; i++) {
|
for (let i = 0; i < event.dataTransfer.files.length; i++) {
|
||||||
files.push(event.dataTransfer.files[i].path);
|
files.push(event.dataTransfer.files[i].path);
|
||||||
if (event.dataTransfer.files[i].type === "") {
|
|
||||||
isAllFile = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isAllFile) {
|
|
||||||
if (event.altKey) {
|
|
||||||
let fileText = "";
|
|
||||||
files.forEach((item) => {
|
|
||||||
// 拖入文件名包含 `)` 或 `]` 的文件以 `file://` 插入后链接解析错误 https://github.com/siyuan-note/siyuan/issues/5786
|
|
||||||
fileText += `[${path.basename(item).replace(/\]/g, "\\]").replace(/\[/g, "\\[")}](file://${item.replace(/\\/g, "\\\\").replace(/\)/g, "\\)").replace(/\(/g, "\\(")})\n`;
|
|
||||||
});
|
|
||||||
insertHTML(protyle.lute.SpinBlockDOM(fileText), protyle);
|
|
||||||
} else {
|
|
||||||
uploadLocalFiles(files, protyle);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
uploadLocalFiles(files, protyle);
|
|
||||||
}
|
}
|
||||||
|
uploadLocalFiles(files, protyle, !event.altKey);
|
||||||
} else {
|
} else {
|
||||||
paste(protyle, event);
|
paste(protyle, event);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,11 +48,8 @@ export const pasteAsPlainText = async (protyle:IProtyle) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (localFiles.length > 0) {
|
if (localFiles.length > 0) {
|
||||||
let fileText = "";
|
uploadLocalFiles(localFiles, protyle, false);
|
||||||
localFiles.forEach((item) => {
|
writeText("");
|
||||||
fileText += `[${path.basename(item).replace(/\]/g, "\\]").replace(/\[/g, "\\[")}](file://${item.replace(/\\/g, "\\\\").replace(/\)/g, "\\)").replace(/\(/g, "\\(")})\n`;
|
|
||||||
});
|
|
||||||
insertHTML(protyle.lute.SpinBlockDOM(fileText), protyle);
|
|
||||||
} else {
|
} else {
|
||||||
insertHTML(protyle.lute.BlockDOM2Content(protyle.lute.InlineMd2BlockDOM(clipboard.readText())), protyle, false, false);
|
insertHTML(protyle.lute.BlockDOM2Content(protyle.lute.InlineMd2BlockDOM(clipboard.readText())), protyle, false, false);
|
||||||
}
|
}
|
||||||
|
|
@ -124,7 +121,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
||||||
localFiles.push(item.childNodes[0].nodeValue);
|
localFiles.push(item.childNodes[0].nodeValue);
|
||||||
});
|
});
|
||||||
if (localFiles.length > 0) {
|
if (localFiles.length > 0) {
|
||||||
uploadLocalFiles(localFiles, protyle);
|
uploadLocalFiles(localFiles, protyle, true);
|
||||||
writeText("");
|
writeText("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +129,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
||||||
} else {
|
} else {
|
||||||
const xmlString = await fetchSyncPost("/api/clipboard/readFilePaths", {});
|
const xmlString = await fetchSyncPost("/api/clipboard/readFilePaths", {});
|
||||||
if (xmlString.data.length > 0) {
|
if (xmlString.data.length > 0) {
|
||||||
uploadLocalFiles(xmlString.data, protyle);
|
uploadLocalFiles(xmlString.data, protyle, true);
|
||||||
writeText("");
|
writeText("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue