mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 00:50:13 +01:00
This commit is contained in:
parent
111a49294e
commit
053f88d0ce
3 changed files with 7 additions and 22 deletions
|
|
@ -169,7 +169,8 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
|||
});
|
||||
const code = processPasteCode(textHTML, textPlain);
|
||||
const range = getEditorRange(protyle.wysiwyg.element);
|
||||
if (nodeElement.getAttribute("data-type") === "NodeCodeBlock") {
|
||||
if (nodeElement.getAttribute("data-type") === "NodeCodeBlock" ||
|
||||
protyle.toolbar.getCurrentType(range).includes("code")) {
|
||||
// 粘贴在代码位置
|
||||
insertHTML(textPlain, protyle);
|
||||
return;
|
||||
|
|
@ -201,25 +202,8 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
|||
highlightRender(protyle.wysiwyg.element);
|
||||
} else if (code) {
|
||||
if (!code.startsWith('<div data-type="NodeCodeBlock" class="code-block" data-node-id="')) {
|
||||
const wbrElement = document.createElement("wbr");
|
||||
range.insertNode(wbrElement);
|
||||
const html = nodeElement.outerHTML;
|
||||
wbrElement.remove();
|
||||
range.deleteContents();
|
||||
const tempElement = document.createElement("span");
|
||||
tempElement.setAttribute("data-type", "code");
|
||||
tempElement.textContent = Constants.ZWSP + code;
|
||||
range.insertNode(tempElement);
|
||||
if (!hasPreviousSibling(tempElement)) {
|
||||
tempElement.insertAdjacentHTML("beforebegin", Constants.ZWSP);
|
||||
}
|
||||
if (hasNextSibling(tempElement)) {
|
||||
tempElement.insertAdjacentHTML("afterend", "<wbr>");
|
||||
} else {
|
||||
tempElement.insertAdjacentHTML("afterend", Constants.ZWSP + "<wbr>");
|
||||
}
|
||||
updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);
|
||||
focusByWbr(protyle.wysiwyg.element, range);
|
||||
// 原有代码在行内元素中粘贴会嵌套
|
||||
insertHTML(code, protyle);
|
||||
} else {
|
||||
insertHTML(code, protyle, true);
|
||||
highlightRender(protyle.wysiwyg.element);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue