mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-27 17:34:06 +01:00
This commit is contained in:
parent
d579e7511f
commit
da11e337aa
6 changed files with 67 additions and 70 deletions
|
|
@ -128,7 +128,7 @@ export const pasteEscaped = async (protyle: IProtyle, nodeElement: Element) => {
|
|||
.replace(/\|/g, "\\|")
|
||||
.replace(/\./g, "\\.");
|
||||
// 转义文本不能使用 DOM 结构 https://github.com/siyuan-note/siyuan/issues/11778
|
||||
pasteText(protyle, clipText, nodeElement, false);
|
||||
paste(protyle, {textPlain: clipText, target: nodeElement as HTMLElement});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
|
@ -228,57 +228,6 @@ export const restoreLuteMarkdownSyntax = (protyle: IProtyle) => {
|
|||
protyle.lute.SetMark(window.siyuan.config.editor.markdown.inlineMark);
|
||||
};
|
||||
|
||||
export const pasteText = async (protyle: IProtyle, textPlain: string, nodeElement: Element, toBlockDOM = true) => {
|
||||
if (protyle && protyle.app && protyle.app.plugins) {
|
||||
for (let i = 0; i < protyle.app.plugins.length; i++) {
|
||||
const response: IObject = await new Promise((resolve) => {
|
||||
const emitResult = protyle.app.plugins[i].eventBus.emit("paste", {
|
||||
protyle,
|
||||
resolve,
|
||||
textHTML: textPlain,
|
||||
textPlain,
|
||||
siyuanHTML: textPlain,
|
||||
files: []
|
||||
});
|
||||
if (emitResult) {
|
||||
resolve(undefined);
|
||||
}
|
||||
});
|
||||
|
||||
if (response?.textPlain) {
|
||||
textPlain = response.textPlain;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const range = getEditorRange(protyle.wysiwyg.element);
|
||||
if (nodeElement.getAttribute("data-type") === "NodeCodeBlock") {
|
||||
// 粘贴在代码位置
|
||||
insertHTML(textPlain, protyle);
|
||||
return;
|
||||
}
|
||||
if (range.toString() !== "") {
|
||||
if (isDynamicRef(textPlain)) {
|
||||
textPlain = textPlain.replace(/'.+'\)\)$/, ` "${range.toString()}"))`);
|
||||
} else if (isFileAnnotation(textPlain)) {
|
||||
textPlain = textPlain.replace(/".+">>$/, `"${range.toString()}">>`);
|
||||
} else {
|
||||
const linkDest = protyle.lute.GetLinkDest(textPlain);
|
||||
if (linkDest) {
|
||||
textPlain = `[${range.toString()}](${linkDest})`;
|
||||
}
|
||||
}
|
||||
}
|
||||
insertHTML(toBlockDOM ? protyle.lute.Md2BlockDOM(textPlain) : textPlain, protyle, false, false, true);
|
||||
|
||||
blockRender(protyle, protyle.wysiwyg.element);
|
||||
processRender(protyle.wysiwyg.element);
|
||||
highlightRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element, protyle);
|
||||
filterClipboardHint(protyle, textPlain);
|
||||
scrollCenter(protyle, undefined, false, "smooth");
|
||||
};
|
||||
|
||||
const readLocalFile = async (protyle: IProtyle, localFiles: string[]) => {
|
||||
if (protyle && protyle.app && protyle.app.plugins) {
|
||||
for (let i = 0; i < protyle.app.plugins.length; i++) {
|
||||
|
|
@ -303,9 +252,16 @@ const readLocalFile = async (protyle: IProtyle, localFiles: string[]) => {
|
|||
uploadLocalFiles(localFiles, protyle, true);
|
||||
};
|
||||
|
||||
export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEvent) & { target: HTMLElement }) => {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEvent | {
|
||||
textHTML?: string,
|
||||
textPlain?: string,
|
||||
}) & {
|
||||
target: HTMLElement
|
||||
}) => {
|
||||
if ("clipboardData" in event || "dataTransfer" in event) {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
}
|
||||
let textHTML: string;
|
||||
let textPlain: string;
|
||||
let siyuanHTML: string;
|
||||
|
|
@ -315,13 +271,16 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
|||
textPlain = event.clipboardData.getData("text/plain");
|
||||
siyuanHTML = event.clipboardData.getData("text/siyuan");
|
||||
files = event.clipboardData.files;
|
||||
} else {
|
||||
} else if ("dataTransfer" in event) {
|
||||
textHTML = event.dataTransfer.getData("text/html");
|
||||
textPlain = event.dataTransfer.getData("text/plain");
|
||||
siyuanHTML = event.dataTransfer.getData("text/siyuan");
|
||||
if (event.dataTransfer.types[0] === "Files") {
|
||||
files = event.dataTransfer.items;
|
||||
}
|
||||
} else {
|
||||
textHTML = event.textHTML
|
||||
textPlain = event.textPlain
|
||||
}
|
||||
|
||||
// Improve the pasting of selected text in PDF rectangular annotation https://github.com/siyuan-note/siyuan/issues/11629
|
||||
|
|
@ -585,3 +544,4 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
|||
scrollCenter(protyle, undefined, false, "smooth");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue